MATLAB plotting syntax error? [closed] - matlab

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.

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)))

Matlab - plot data from array of structs [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 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]);

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.

Distance measurement in Matlab [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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.
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.
Improve this question
I have tried the code from the link Ear Image Processing - Finding the point of intersection of line and curve in MATLAB
but seem to get an error as dist2s is undefined on matlab R2013a.Can anyone help me out
That's because you need to create the function (isn't defined by MatLab itself). Try saving this code in a file called dist2s.m and then setting the folder where it's located like current folder:
function out = dist2s(pt1,pt2)
out = NaN(size(pt1,1),size(pt2,1));
for m = 1:size(pt1,1)
for n = 1:size(pt2,1)
if(m~=n)
out(m,n) = sqrt( (pt1(m,1)-pt2(n,1)).^2 + (pt1(m,2)-pt2(n,2)).^2 );
end
end
end
return;
The code is provided in the same answer you refer to.

Error: Undefined function or variable linspace [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 1 year ago.
Improve this question
When I am trying to use linspace in MATLAB I am getting the above error. How do I resolve it?
I am using linspace in a very simple statement:
t= linspace(0,8760,876);
Why don't you try to check internal matlab path? If you get that error is because Matlab cannot find the definition of the function. Thought it is weird as it is a basic function.
It's probably a path issue. Run restoredefaultpath.