2D Matlab Plot help please

1 Ansicht (letzte 30 Tage)
yasmin
yasmin am 26 Jul. 2012
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 Kommentar
Azzi Abdelmalek
Azzi Abdelmalek am 27 Jul. 2012
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

Melden Sie sich an, um zu kommentieren.

Antworten (3)

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

Image Analyst
Image Analyst am 27 Jul. 2012
Bearbeitet: Image Analyst am 27 Jul. 2012
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 am 27 Jul. 2012
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)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by