Matlab - plot data from array of structs [closed] - matlab

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have an array of structs. Every struct holds a set of data for one single measure. Matlab gives me an error when I try to plot this data.
Expected one output from a curly brace or dot indexing expression, but there were 361 results.
How should I rewrite my plot code?
plot(result.structArray_A(:).nonArrayValue_X, result.structArray_A(:).nonArrayValue_Y);

I have found a solution. Simply writing the following does work, even if the syntax does look odd:
plot([result.structArray_A.nonArrayValue_X], [result.structArray_A.nonArrayValue_Y]);

Related

Array indices must be positive matlab [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am new to MATLAB, I have created a triangle, I used the code as below to find all coordinates of x,y.
side_1=[linspace(3,5,100);linspace(2,3,100)]
side_2=[linspace(5,4,100);linspace(3,5,100)]
side_3=[linspace(4,3,100);linspace(5,2,100)]
all_coordinates=[side_1,side_2,side_3]
I used the code as below to find angles.
angles=zeros(300,1);
for i=1:300
angles(i)=atan(all_coordinates(2,i)/all_coordinates(1,i))*180/pi
end
Since view point is flatview, y=0, x=angles
I used this code to plot angles.
for i = range(length(angles))
scatter(angles(i),0)
end
Got error array indices must be positive integers or logical values.
Not sure what you are trying to do with the loop but the problem is that you last loop is wrong.
range(length(angles)) =0, you should use for i=1:length(angles) instead
In addition the two loops are unnecessary. Not sure what you are trying to do with the scatter plot, but you can just write:
angles=atan(all_coordinates(2,:)./all_coordinates(1,:))*180/pi
figure
scatter(angles,zeros(1,length(angles)))

I can't find all the errors occurring in my codes [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
For matalb there's an error at line 9, where I define dy(1), but it doesn't say what kind of error.
function dy=pred_prey(t,y)
k=1;
a=2/3;
d=4/3;
f=#(x)cos(x.^2)
r=#(t)integral(f,0,t);
mu=#(t)13/20-(3/5)*exp(-(3/t));
dy(1)=(y(1)+k)*r-a*y(1)*y(2);
dy(2)=-mu*y(2)+d*y(1)*y(2);
dy=dy';
You define r as an anonymous function, but you don't pass any arguments to it when you call it on line 9. The line should be (I assume):
dy(1) = (y(1)+k)*r(t)-a*y(1)*y(2);
Incidentally, you're going to have the same problem on the next line where you call mu with no arguments as well.

matlab draw a line using user input values [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 months ago.
Improve this question
I want to draw a line using the inputs for values x1,y1 and x2,y2 from the gui edit text box and plot them on the axes.
function
You are trying to convert the graphics handle itself to a number rather than converting the contents of the uicontrol to a number. To get the value, you'll want to use the 'String' property of the uicontrol instead.
x1 = str2double(get(handles.edit1, 'String'));
You will want to do the same for all user-supplied values.

MATLAB plotting syntax error? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I watched a video titled "Writing a matlab program" and tried to use the syntax exactly, yet I still can't see how I've made an error...can you please help?
My code is simply
x= [-10:0.1:10];
y=2x^2-x + 1;
plot (x,y)
I'm getting a parse error at x and I have no idea what that means..
Matlab cannot parse 2x. Multiplication requires the * symbol. Either * or .* will work in this case.
Your next problem will be the use of ^ instead of .^ —this time you're going to have to include the dot. Google for "elementwise" operators in matlab to understand what difference the dot makes.

I is not a real numeric array of class SINGLE [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm using the computer vision: VLfeat library to compute a HOG descriptor of an image, and after inputing this code:
cellSize = 8 ;
hog = vl_hog(im, cellSize, 'verbose') ;
I get this error in MATLAB, and when I google it I really can't find any possible explanation:
Error using vl_hog
I is not a real numeric array of class SINGLE.
After going over the code (found here) I'm also not sure what the variable I is:
Hopefully, I haven't missed something elementary ...
library source
As the asker already found out, the I refers to the first input argument.
Hence this should solve the problem:
hog = vl_hog(single(im), cellSize, 'verbose')