From: Matt on
I want to plot a cell array (that are of different length). How do I do that?

For example,
x1=[1 4 8 10]
y1=[10 20 30 40]

x1=[1 2 3]
y2=[5 10 15]

Cx{1}=x1
Cx{2}=x2

Cy{1}=y1
Cy{2}=y2

plot(Cx{1:end},Cy{1:end})


I get the following message

??? Error using ==> plot
Vectors must be the same lengths.

I don't want to change the length of the vectors by padding. I also don't want to plot in a loop because then I will have to put in different colors, and also I shouldn't have to use a loop...

Thanks
From: us on
"Matt " <matt321a(a)gmail.com> wrote in message <i3mhcu$ek7$1(a)fred.mathworks.com>...
> I want to plot a cell array (that are of different length). How do I do that?
>
> For example,
> x1=[1 4 8 10]
> y1=[10 20 30 40]
>
> x1=[1 2 3]
> y2=[5 10 15]
>
> Cx{1}=x1
> Cx{2}=x2
>
> Cy{1}=y1
> Cy{2}=y2
>
> plot(Cx{1:end},Cy{1:end})
>
>
> I get the following message
>
> ??? Error using ==> plot
> Vectors must be the same lengths.
>
> I don't want to change the length of the vectors by padding. I also don't want to plot in a loop because then I will have to put in different colors, and also I shouldn't have to use a loop...
>
> Thanks

one of the many solutions

cx={[1 4 8 10],1:3};
cy={[10 20 30 40],[5,10,15]};
for i=1:numel(cx)
line(cx{i},cy{i});
end

us
From: Walter Roberson on
Matt wrote:
> I want to plot a cell array (that are of different length). How do I do
> that?
>
> For example,
> x1=[1 4 8 10]
> y1=[10 20 30 40]
>
> x1=[1 2 3]
> y2=[5 10 15]
>
> Cx{1}=x1
> Cx{2}=x2
>
> Cy{1}=y1
> Cy{2}=y2
>
> plot(Cx{1:end},Cy{1:end})
>
>
> I get the following message
>
> ??? Error using ==> plot
> Vectors must be the same lengths.
>
> I don't want to change the length of the vectors by padding. I also
> don't want to plot in a loop because then I will have to put in
> different colors, and also I shouldn't have to use a loop...

Using Cx{1:end}, Cy{1:end} is like writing a

Cx{1}, Cx{2}, Cy{1}, Cy{2}

X and Y pairs must alternate for plot() so that is like trying to plot
Cx{1} against Cx{2} which is not possible because those are different sizes.

Try

T = [Cx;Cy];

plot(T{:})
From: Matt on
Walter Roberson <roberson(a)hushmail.com> wrote in message <mJA7o.3958$EF1.770(a)newsfe14.iad>...
> Matt wrote:
> > I want to plot a cell array (that are of different length). How do I do
> > that?
> >
> > For example,
> > x1=[1 4 8 10]
> > y1=[10 20 30 40]
> >
> > x1=[1 2 3]
> > y2=[5 10 15]
> >
> > Cx{1}=x1
> > Cx{2}=x2
> >
> > Cy{1}=y1
> > Cy{2}=y2
> >
> > plot(Cx{1:end},Cy{1:end})
> >
> >
> > I get the following message
> >
> > ??? Error using ==> plot
> > Vectors must be the same lengths.
> >
> > I don't want to change the length of the vectors by padding. I also
> > don't want to plot in a loop because then I will have to put in
> > different colors, and also I shouldn't have to use a loop...
>
> Using Cx{1:end}, Cy{1:end} is like writing a
>
> Cx{1}, Cx{2}, Cy{1}, Cy{2}
>
> X and Y pairs must alternate for plot() so that is like trying to plot
> Cx{1} against Cx{2} which is not possible because those are different sizes.
>
> Try
>
> T = [Cx;Cy];
>
> plot(T{:})


Exactly what I am loooking for. Thanks for the explanation.
From: Matt on
Walter Roberson <roberson(a)hushmail.com> wrote in message <mJA7o.3958$EF1.770(a)newsfe14.iad>...
> Matt wrote:
> > I want to plot a cell array (that are of different length). How do I do
> > that?
> >
> > For example,
> > x1=[1 4 8 10]
> > y1=[10 20 30 40]
> >
> > x1=[1 2 3]
> > y2=[5 10 15]
> >
> > Cx{1}=x1
> > Cx{2}=x2
> >
> > Cy{1}=y1
> > Cy{2}=y2
> >
> > plot(Cx{1:end},Cy{1:end})
> >
> >
> > I get the following message
> >
> > ??? Error using ==> plot
> > Vectors must be the same lengths.
> >
> > I don't want to change the length of the vectors by padding. I also
> > don't want to plot in a loop because then I will have to put in
> > different colors, and also I shouldn't have to use a loop...
>
> Using Cx{1:end}, Cy{1:end} is like writing a
>
> Cx{1}, Cx{2}, Cy{1}, Cy{2}
>
> X and Y pairs must alternate for plot() so that is like trying to plot
> Cx{1} against Cx{2} which is not possible because those are different sizes.
>
> Try
>
> T = [Cx;Cy];
>
> plot(T{:})

Is there any way to add the same or different marker to the different lines
When I try
plot(T{:},'-s')

This just gives one of the lines square markers, where I would have expected it to give all the lines square markers...why is that?

When I try to make a cell array of markers and do the following

for i=1:length(T)
markers{i}='-s';
end
plot(T{:},markers{:});

I get the following

??? Error using ==> plot
Invalid property found.
Object Name : line
Property Name : '-s'.


Thanks again!

 |  Next  |  Last
Pages: 1 2
Prev: imresize again
Next: Auditory Toolbox (M. Slaney)