2D Matlab Plot help please

2 次查看(过去 30 天)
yasmin
yasmin 2012-7-26
Hi all can someone please help me here for matlab plot, I am using the matlab code below but getting an error message.
plot(xdata,Revs)
size xdata is 5 by 1 and size of Revs is 1 by 3000
am getting an error message which says "Vectors must be the same lengths"
what am trying to do is to plot xdata on the y axis and the Revs on the x axis.
  1 个评论
Azzi Abdelmalek
Azzi Abdelmalek 2012-7-27
that means that you want to plot Revs(xdata), if xdata is 5 by 1; Revs must be too. Unless there is something else you want to do

请先登录,再进行评论。

回答(3 个)

Wayne King
Wayne King 2012-7-26
The x and y variables must have the same length. What relationship is there between xdata and Revs?

Image Analyst
Image Analyst 2012-7-27
编辑:Image Analyst 2012-7-27
Just get rid of xdata if you want the x-axis to be the array index,
plot(Revs, 'bo-');
or if you need the values for the x-axis tick marks, then try this:
xValues = linspace(min(xdata), max(xdata), length(Revs));
plot(xValues, Revs, 'bo-');
Wait - scratch that. You need to reverse those since you want to "plot xdata on the y axis and the Revs on the x axis":
yValues = linspace(min(xdata), max(xdata), length(Revs));
plot(Revs, yValues, 'bo-'); % Revs is the x and yvalues (i.e. xdata) is the y
See if that will produce a plot that looks like how you want it to look.

Azzi Abdelmalek
Azzi Abdelmalek 2012-7-27
try this code
xdata=[1 5 9 13 17 21]';Revs=rand(1,3000); %for example
plot(Revs);
ax1=gca;pos=double(get(ax1,'position'));
set(ax1,'visible','off')
ax2=axes('position',pos,'Color' ,'none')
x1=min(xdata);x2=max(xdata);n=length(xdata)-1
set(ax2,'Ylim',[min(Revs) max(Revs)], 'Xlim',[x1 x2],'xtick',x1:(x2-x1)/n:x2)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by