0
votes

Am trying to plot 2 variable of different size length in matlab GUI using push button, but because the variables are of different length it will not work,is there a way i can make it to plot.

d= pdist([x,y,z],'euclidean') ;  % value of my distance   
dd= 1:10:d;            % interval and end 'd' value                                 
FSL=-120;           %value of free space loss get from the GUI   
DFSL= 1:10:FSL         %interval and end at FSL value

plot(dd,DFSL)

The plot code didnt work coming back with an error " Error using plot Vectors must be the same lengths"

1
Are you trying to plot dd and DFSL against each other as an (x,y) pair? Or do you just want to see both variables plotted against their own index? - Doresoom
am trying to as (x,y) pair.Thanks - user3220520
You can't plot two vectors of unequal lengths as an (x,y) pair, as the longer vector will run out of corresponding values in the shorter vector. If you know the index of the values in the longer vector that you want to compare, then: plot(shortVec,longVec(index)) should work, where index is an integer vector the same length as shortVec, with no values greater than numel(longVec). - Doresoom
You set the interval for dd and DFSL to 10. Why is this? Do you know know that time x-vector for dd starts at 1 and ends at d? - CatsLoveJazz
yes i want it to plot dd against DFSL at every 10 interval - user3220520

1 Answers

1
votes

You can plot vectors of two different lengths, but not against each other. You have used the syntax

plot(x,y)

which means for every element in vector x, there should be a corresponding element in vector y. In your case, you do not have this, hence the error.

You can plot like this though:

plot(x)
figure;
plot(y)

If you are looking to plot them in a single plot, subplot will be useful.