Scatter() working but not Plot()

Hello,
I am having trouble getting plot() to work. My code works if I use scatter() instead of plot(). If I used plot(), then I get Error in plot(x,y). Can someone please tell me why plot is not working? Thanks!
x = 1:10;
y = x.^2;
figure
hold on
plot(x,y)
hold off

6 个评论

What is the FULL text of the error message you receive? Show everything displayed in red.
My full error is:
Error in PostProcessing_filetest (line 269)
plot(x,y)
No, that's not EVERYTHING in red. Most importantly, the actual error message is not there. Please include everything. Put
clc
as the first line in your code, then copy the entire contents of the command window (after it errors) and paste it back here. For me the code runs and products this:
I suspect...he have another function on the name plot. He is not using inbuilt function plot. What does which plot display?
My guess is that there is a variable named plot
This is the full error. I am not sure why there is an indexing issue.
>> PostProcessing_filetest
Index exceeds matrix dimensions.
Error in PostProcessing_filetest (line 287)
plot(x,y)

请先登录,再进行评论。

 采纳的回答

madhan ravi
madhan ravi 2018-11-2
编辑:madhan ravi 2018-11-2

0 个投票

Delete another .m file which has the same name plot.m or rename it

9 个评论

Thank you! Deleting plot.m and rerunning it seems to work. However, if I want to create plots using a loop, will this cause an issue?
Anytime :) Nie ma za co! no it won’t cause any problem if and only if you know to use it properly.
Ok I am trying to run plots in a for loop here. The figure pops up and so does the first subplot but I get the same error (Index exceeds matrix dimensions. Error in PostProcessing_filetest (line 281) plot(y,xt(:,:,i,j)) ) It runs perfectly fine if I used scatter() instead of plot() though. There is no plot.m defined beforehand so I'm wondering if its my loop.
for j = index
figure(fignum)
fignum = fignum + 1;
hold on
for i = 1:numfiles
subplot(numfiles,1,i)
y = Farray(2:end);
yt = transpose(y);
x(:,:,i,j) = NewAmp(:,:,i,j);
xt(:,:,i,j) = transpose(x(:,:,i,j));
xlabel('Frequecy(Hz)')
ylabel('Amplitude')
plot(y,xt(:,:,i,j))
end
hold off
end
Without datas it is hard to interpret , it would be better if you post a new question with all the necessary details
Based on the error message you posted you haven't defined your own function named plot, but you have created a variable named plot earlier in this script or function (or in the caller workspace if this is a script file.) In that case the last line of that for loop becomes an attempt to index into that variable rather than an attempt to call the function.
That makes sense. Do you know why scatter() works then? This loop is the first time I am using plot() so I am not sure why that would be any different than scatter(). I could post more of the script but the entire one is close too 300 lines long. Thanks!
You can attach the script.
"That makes sense. Do you know why scatter() works then? This loop is the first time I am using plot() so I am not sure why that would be any different than scatter()."
Because you created a variable named plot, but did not create a variable named scatter.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Annotations 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by