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:
can someone please explain this matlab command for me

Subject: can someone please explain this matlab command for me

From: evan evan

Date: 19 Jan, 2011 21:38:04

Message: 1 of 10

this command :

 out2 = reshape(out(1:(round(size(out,2)/5)-1)*5),[5 (round(size(out,2)/5)-1)]);
 out2 = out2';
 out2 = str2NUM(out2(1:end,2:end));


especially this part :
 out2 = reshape(out(1:(round(size(out,2)/5)-1)*5),[5 (round(size(out,2)/5)-1)]);


please i need a detailed explanation for the code . its crucial that i understand what it means letter by letter,


Thank you

Subject: can someone please explain this matlab command for me

From: Sean de

Date: 19 Jan, 2011 21:57:05

Message: 2 of 10

"evan evan" <evan349343@yahoo.com> wrote in message <ih7ljs$9i9$1@fred.mathworks.com>...
> this command :
>
> out2 = reshape(out(1:(round(size(out,2)/5)-1)*5),[5 (round(size(out,2)/5)-1)]);
> out2 = out2';
> out2 = str2NUM(out2(1:end,2:end));
>
>
> especially this part :
> out2 = reshape(out(1:(round(size(out,2)/5)-1)*5),[5 (round(size(out,2)/5)-1)]);
>
>
> please i need a detailed explanation for the code . its crucial that i understand what it means letter by letter,
>
>
> Thank you

okay:
out = magic(8);

%now run each individual piece of the code

size(out,2)
size(out,2)/5
round(size(out,2)/5)-1
1:((round(size(out,2)/5)-1)*5)
out(1:((round(size(out,2)/5)-1)*5))
[5 (round(size(out,2)/5)-1)]
doc reshape

This is how you learn to program; take complicated things and break them down in to a lot of small ones

Subject: can someone please explain this matlab command for me

From: TideMan

Date: 19 Jan, 2011 22:00:00

Message: 3 of 10

On Jan 20, 10:38 am, "evan evan" <evan349...@yahoo.com> wrote:
> this command :
>
>  out2 = reshape(out(1:(round(size(out,2)/5)-1)*5),[5 (round(size(out,2)/5)-1)]);
>  out2 = out2';
>  out2 = str2NUM(out2(1:end,2:end));
>
> especially this part :
>  out2 = reshape(out(1:(round(size(out,2)/5)-1)*5),[5 (round(size(out,2)/5)-1)]);
>
> please i need a detailed explanation for the code . its crucial that i understand what it means letter by letter,
>
> Thank you

What effort have YOU made to understand this yourself?
I suspect none.
Yet you say it is crucial that you understand what it means letter by
letter!!

Take the line concerned and break it down into its parts, printing
each bit to the screen:
size(out,2)
size(out,2)/5
round(size(out,2)/5
etc
etc

Subject: can someone please explain this matlab command for me

From: Think two, count blue.

Date: 19 Jan, 2011 21:59:22

Message: 4 of 10

On 11-01-19 03:38 PM, evan evan wrote:
> this command :
> out2 = reshape(out(1:(round(size(out,2)/5)-1)*5),[5 (round(size(out,2)/5)-1)]);
> out2 = out2';
> out2 = str2NUM(out2(1:end,2:end));
>
>
> especially this part :
> out2 = reshape(out(1:(round(size(out,2)/5)-1)*5),[5 (round(size(out,2)/5)-1)]);
>
>
> please i need a detailed explanation for the code . its crucial that i
> understand what it means letter by letter,

Looks to me as if the code takes a row vector named "out", find the complete
number of groups of 5 that will fit in it, extracts those out, reshapes it to
5 down by as many columns are as needed across, then transposed the result to
get to the values 5 across and however many lines are needed downward. Then
out of that, it extracts the last 4 columns and converts the resulting array
to string, suitable for printing 4 columns across.

I have no clues from the code as to why it wants to skip the first column on
output.

Subject: can someone please explain this matlab command for me

From: Sean de

Date: 19 Jan, 2011 22:09:05

Message: 5 of 10

"Think two, count blue." <roberson@hushmail.com> wrote in message
> Looks to me as if the code takes a row vector named "out",

That's a blind assumption.

Subject: can someone please explain this matlab command for me

From: Think two, count blue.

Date: 19 Jan, 2011 22:19:31

Message: 6 of 10

On 11-01-19 04:09 PM, Sean de wrote:
> "Think two, count blue." <roberson@hushmail.com> wrote in message
>> Looks to me as if the code takes a row vector named "out",
>
> That's a blind assumption.

Yeh, but the code makes sense if that assumption is made, whereas it errors
out if given a column vector.

Taking another glance, it looks like my analysis may have been wrong on some
boundary conditions involving vectors that were not exact multiples of 5 in
length, and it looks like in some cases it misses a trailing complete multiple
of 5 that it could do. I think the coder make a mistake in using round()-1
instead of floor()

Subject: can someone please explain this matlab command for me

From: ImageAnalyst

Date: 20 Jan, 2011 02:48:35

Message: 7 of 10

evan evan:
Here's my explanation of that code : "It tries to make a long
complicated process as short, compact, and cryptic as possible by
avoiding breaking the process into more steps that would make the code
more understandable and maintainable." But of course, you already
know that.

Subject: can someone please explain this matlab command for me

From: evan evan

Date: 23 Jan, 2011 04:10:06

Message: 8 of 10

well. everybody says that i didnt spend time in understanding the code and it should be easy if u cut it down .

but so far no body explained it ~!!!!!!

s = serial('COM22');
out = fscanf(s);

out2 = reshape(out(1: (round(size(out,2)/5)-1)*5),[5 (round(size(out,2)/5)-1)]);

Subject: can someone please explain this matlab command for me

From: Think blue, count two.

Date: 23 Jan, 2011 04:48:07

Message: 9 of 10

On 22/01/11 10:10 PM, evan evan wrote:
> well. everybody says that i didnt spend time in understanding the code
> and it should be easy if u cut it down .
> but so far no body explained it ~!!!!!!
>
> s = serial('COM22'); out = fscanf(s);
> out2 = reshape(out(1: (round(size(out,2)/5)-1)*5),[5
> (round(size(out,2)/5)-1)]);

I explained what the code *does* three days ago.

Are you still looking for a clause by clause explanation? If so, then
you'd better let us know how far back you need us to start. Can we
assume that you know how subtraction works, for example? Multiplication?
rounding? size()? reshape()?

Subject: can someone please explain this matlab command for me

From: evan evan

Date: 23 Jan, 2011 05:11:03

Message: 10 of 10

"Think blue, count two." <roberson@hushmail.com> wrote in message <cqO_o.763$BE3.268@newsfe08.iad>...
> On 22/01/11 10:10 PM, evan evan wrote:
> > well. everybody says that i didnt spend time in understanding the code
> > and it should be easy if u cut it down .
> > but so far no body explained it ~!!!!!!
> >
> > s = serial('COM22'); out = fscanf(s);
> > out2 = reshape(out(1: (round(size(out,2)/5)-1)*5),[5
> > (round(size(out,2)/5)-1)]);
>
> I explained what the code *does* three days ago.
>
> Are you still looking for a clause by clause explanation? If so, then
> you'd better let us know how far back you need us to start. Can we
> assume that you know how subtraction works, for example? Multiplication?
> rounding? size()? reshape()?


im new in matlab. im using matlab to represent some data .im not trying to be profissional .

i would appreciate it if you could do detailed explanation for the size round()-1 and reshape(1:x,[])

im not looking for easy way out. i looked into mathworks tutoruals for size , reshape ..etc, but all the examples are simple and not as complicated.
  
this reshape function deals with x,y,z, im trying to add another variable , thats why i need to understand it so i can manipulate the values for my needs.

out = fscanf(s);
    if(sum(size(out))>0)

      out2 = reshape(out(1:(round(size(out,2)/5)-1)*5),[5 (round(size(out,2)/5)-1)]);
      out2 = out2';
      out2 = str2NUM(out2(1:end,2:end));

       
Thank you

Tags for this Thread

No tags are associated with 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