save matrixs in different names

9 ビュー (過去 30 日間)
Ayda
Ayda 2011 年 10 月 9 日
Good morning\evening
I have written this code that gave me 30 [1*30] matrix
I try to save each matrix [1*30] in different names so I can later combine them in one matrix[30*30] using [mat1;mat;...;]
I tried it using for loop in different ways but i have errors
Can you help me =)?!
**********************************
function C=OneCamera(x,y)
LCamera = 5;
WCamera = 6;
LArea = 5;
WArea = 6;
for x=1:LCamera
for y=1:WCamera
for i=1:LArea
for j=1:WArea
d=(i-x)^2+(j-y)^2;
if d<16
C(i,j)=1;
else
C(i,j)=0;
end;
end;
end
x
y
C
A= reshape (C',1,30)
end
end
end
  3 件のコメント
Walter Roberson
Walter Roberson 2011 年 10 月 9 日
Duplicate is at http://www.mathworks.com/matlabcentral/answers/17790-combine-30-1-30-matrix-to-one-matrix-30-30

サインインしてコメントする。

採用された回答

Dr. Seis
Dr. Seis 2011 年 10 月 9 日
It may not be efficient, but before your "for" loops you can define an empty matrix:
mat = [];
Then inside your "for" loop after you define your 1x30 matrix "A", you would just need to do:
mat(end+1,:) = A;
Is this a possible work around?
For larger matrices you would do well to preallocate the size of the matrix - for example:
mat = zeros(30,30);
Then populate each row of that matrix after each iteration.
  1 件のコメント
Ayda
Ayda 2011 年 10 月 9 日
thanks a lot

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by