Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Simple plotting question

Subject: Simple plotting question

From: Nathan Jensen

Date: 17 Aug, 2010 17:47:05

Message: 1 of 6

I'm trying to do something like this:

A{1}={...}
A{2}={...}
A{3}={1 2 3 [] 5 6}
A{4}={...}

B=[1 2 3 4 5 6]

for i=1:4
plot(A{i},B)
end

Any ideas?
Thanks,
Nate

Subject: Simple plotting question

From: Andy

Date: 17 Aug, 2010 17:55:21

Message: 2 of 6

"Nathan Jensen" <swishidgenj@yahoo.com> wrote in message <i4ehup$amd$1@fred.mathworks.com>...
> I'm trying to do something like this:
>
> A{1}={...}
> A{2}={...}
> A{3}={1 2 3 [] 5 6}
> A{4}={...}
>
> B=[1 2 3 4 5 6]
>
> for i=1:4
> plot(A{i},B)
> end
>
> Any ideas?
> Thanks,
> Nate

What exactly is going wrong? Are the graphs not what you want them to be? Are you getting an error message which you are for some reason not showing us? My best guess at your problem is that you're getting an error message because A{i} is a cell. Don't wrap the right hand sides of your assignments in curly braces. But that's just a guess.

Subject: Simple plotting question

From: Sean

Date: 17 Aug, 2010 17:59:06

Message: 3 of 6

"Nathan Jensen" <swishidgenj@yahoo.com> wrote in message <i4ehup$amd$1@fred.mathworks.com>...
> I'm trying to do something like this:
>
> A{1}={...}
> A{2}={...}
> A{3}={1 2 3 [] 5 6}
> A{4}={...}
>
> B=[1 2 3 4 5 6]
>
> for i=1:4
> plot(A{i},B)
> end
>
> Any ideas?
> Thanks,
> Nate

figure;
hold on %don't overwrite
my_colors = ['rgkb'] %red green black blue
for ii=1:4 %don't use i as it is used for imaginary numbers
   plot(A{ii},B,c(ii));
end

Subject: Simple plotting question

From: Nathan Jensen

Date: 17 Aug, 2010 18:11:08

Message: 4 of 6

"Andy " <myfakeemailaddress@gmail.com> wrote in message <i4eie9$b6m$1@fred.mathworks.com>...
> "Nathan Jensen" <swishidgenj@yahoo.com> wrote in message <i4ehup$amd$1@fred.mathworks.com>...
> > I'm trying to do something like this:
> >
> > A{1}={...}
> > A{2}={...}
> > A{3}={1 2 3 [] 5 6}
> > A{4}={...}
> >
> > B=[1 2 3 4 5 6]
> >
> > for i=1:4
> > plot(A{i},B)
> > end
> >
> > Any ideas?
> > Thanks,
> > Nate
>
> What exactly is going wrong? Are the graphs not what you want them to be? Are you getting an error message which you are for some reason not showing us? My best guess at your problem is that you're getting an error message because A{i} is a cell. Don't wrap the right hand sides of your assignments in curly braces. But that's just a guess.

I'm sorry if I didn't make myself clear, here is the code again:

A{1}={1 2 3 4 5 6}
A{2}={1 2 3 4 5 6}
A{3}={1 2 3 [] 5 6}
A{4}={1 2 3 4 5 6}

B=[1 2 3 4 5 6]

for i=1:4
    figure
    plot(A{i},B)
end

if you try to run this code, you will get the following error message:

??? Error using ==> plot
Conversion to double from cell is not possible.

The reason that I think that I need to use cells is because
A{3}(4) = []

and if I simply stated
A{3}=[1 2 3 [] 5 6]
or
A(3)={[1 2 3 [] 5 6]}

then
A{3}=[1 2 3 5 6]

which completely misses the empty cell []

do you understand what I am trying to say?

Subject: Simple plotting question

From: Walter Roberson

Date: 17 Aug, 2010 18:17:15

Message: 5 of 6

Nathan Jensen wrote:
> I'm trying to do something like this:
>
> A{1}={...}
> A{2}={...}
> A{3}={1 2 3 [] 5 6}
> A{4}={...}
>
> B=[1 2 3 4 5 6]
>
> for i=1:4
> plot(A{i},B)
> end
>
> Any ideas?

Use nan instead of []

Subject: Simple plotting question

From: Nathan Jensen

Date: 17 Aug, 2010 18:26:04

Message: 6 of 6

solid dude that's how you do it.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us