hi,
I'm trying to create a matrix of 8X12 by the code below but I get a matrix of 12X12.
does anyone understands where is my mistake?
genes_val=zeros(8,12)
val_ind=1
for j=1:12;
for i=1:8;
genes_vals(i,j)=mean_qty(val_ind)
val_ind=val_ind+1
end
end
Thanks!
|
|
0
|
|
|
|
Reply
|
pixel
|
1/28/2011 7:45:03 AM |
|
"pixel" wrote in message <ihts5v$8vq$1@fred.mathworks.com>...
> hi,
> I'm trying to create a matrix of 8X12 by the code below but I get a matrix of 12X12.
> does anyone understands where is my mistake?
>
> genes_val=zeros(8,12)
> val_ind=1
> for j=1:12;
> for i=1:8;
> genes_vals(i,j)=mean_qty(val_ind)
> val_ind=val_ind+1
> end
> end
>
> Thanks!
it's working just fine
genes_vals is 8X12
you also don't need the ; in the for line, for j=1:12; is the same as for j=1:12
|
|
0
|
|
|
|
Reply
|
Paulo
|
1/28/2011 8:03:04 AM
|
|
"Paulo Silva" wrote in message <ihtt7o$85t$1@fred.mathworks.com>...
> "pixel" wrote in message <ihts5v$8vq$1@fred.mathworks.com>...
> > hi,
> > I'm trying to create a matrix of 8X12 by the code below but I get a matrix of 12X12.
> > does anyone understands where is my mistake?
> >
> > genes_val=zeros(8,12)
> > val_ind=1
> > for j=1:12;
> > for i=1:8;
> > genes_vals(i,j)=mean_qty(val_ind)
> > val_ind=val_ind+1
> > end
> > end
> >
> > Thanks!
>
> it's working just fine
> genes_vals is 8X12
>
> you also don't need the ; in the for line, for j=1:12; is the same as for j=1:12
Instead you might want to add ; in the end of all other lines.
I found no mistakes in the code, assuming you really want 8 x 12 matrix.
More "MATLAB-type" code producing the same result could be:
genes_val=zeros(8,12);
genes_val(:) = mean_qty;
or
genes_val=reshape(mean_qty,8,12);
|
|
0
|
|
|
|
Reply
|
Pekka
|
1/28/2011 11:00:06 AM
|
|
On 28/01/11 5:00 AM, Pekka Kumpulainen wrote:
> "Paulo Silva" wrote in message <ihtt7o$85t$1@fred.mathworks.com>...
>> "pixel" wrote in message <ihts5v$8vq$1@fred.mathworks.com>...
>> > hi,
>> > I'm trying to create a matrix of 8X12 by the code below but I get a
>> matrix of 12X12.
>> > does anyone understands where is my mistake?
>> > > genes_val=zeros(8,12)
>> > val_ind=1
>> > for j=1:12;
>> > for i=1:8;
>> > genes_vals(i,j)=mean_qty(val_ind)
>> > val_ind=val_ind+1
>> > end
>> > end
>> > > Thanks!
>>
>> it's working just fine genes_vals is 8X12
>>
>> you also don't need the ; in the for line, for j=1:12; is the same as
>> for j=1:12
>
> Instead you might want to add ; in the end of all other lines.
> I found no mistakes in the code, assuming you really want 8 x 12 matrix.
> More "MATLAB-type" code producing the same result could be:
> genes_val=zeros(8,12);
> genes_val(:) = mean_qty;
> or
> genes_val=reshape(mean_qty,8,12);
In order to be equivalent to the original code, mean_qty would have to
be an array or a vectorized function, and the references to mean_qty
would have to be changed to mean_qty(1:8*12)
|
|
0
|
|
|
|
Reply
|
Think
|
1/28/2011 12:00:25 PM
|
|
|
3 Replies
395 Views
(page loaded in 0.058 seconds)
Similiar Articles: Creating a matrix using a for loop - comp.soft-sys.matlab ...hi, I'm trying to create a matrix of 8X12 by the code below but I get a matrix of 12X12. does anyone understands where is my mistake? genes_val=z... Using nested for loops for Matrix multiplication - comp.soft-sys ...Hello everyone, Homework help: I was assigned a problem that requires me to use nested for loops for matrix multiplication. I have the first two f... Creating Variables thru loop or ? - comp.soft-sys.matlab ...Creating a matrix using a for loop - comp.soft-sys.matlab ... Creating a matrix using a for loop - comp.soft-sys.matlab ... Creating Variables thru loop or ? - comp.soft ... Tridiagonal matrix - Gaussian elimination, loop - comp.soft-sys ...I have to seek help after running out of resources on this. I have a 39X39 tridiagonal matrix. We are not allowed to use Matrix operations in matlab... How to get matrix output by using parfor loop - comp.soft-sys ...Hi All, I am a new user of Parallel Computing Toolbox. Would you please help me to figure out how to get a matrix output by using parfor loop. Here i... Please help, how to use "for loop" to list out the coordinate ...Please help, how to use "for loop" to list out the coordinate/index of matrix elements in every row Follow How to repeat a vector to creat a matrix - comp.soft-sys.matlab ...Creating a matrix using a for loop - comp.soft-sys.matlab ... How to repeat a vector to creat a matrix - comp.soft-sys.matlab ... How can I create a matrix from a repeated ... Storing multiple Matrix from 'for' loop - comp.soft-sys.matlab ...MATLAB Basics video: Storing data in a matrix from a loop | File ..... use the FOR loop index ... Please help, how to use "for loop" to list out the coordinate ... If there are ... adding in a loop? - comp.soft-sys.matlabinstead of For loop - comp.soft-sys.matlab Creating a matrix using a for loop - comp.soft-sys.matlab ... instead of For loop - comp.soft-sys.matlab adding in a loop ... instead of For loop - comp.soft-sys.matlabCreating a matrix using a for loop - comp.soft-sys.matlab ... instead of For loop - comp.soft-sys.matlab adding in a loop? - comp.soft-sys.matlab Instead you might want to ... create a matrix (n,m) using a for loop - Newsreader - MATLAB CentralHi everyone I tried to get a resulting matrix (n,m) using the below code. But i filaed to get it. How can I correct the code to get the result I want? loops in matlabWe will assume that you know how to create vectors and ... use loops and perform row operations on a matrix, Gaussian Elimination can be performed using only two loops ... 7/24/2012 12:19:03 AM
|