create n arrays in matlab

58 ビュー (過去 30 日間)
hala
hala 2013 年 3 月 31 日
i want to create n array with size m where m,n are input to the function how to make this ?

回答 (2 件)

Cedric
Cedric 2013 年 3 月 31 日
編集済み: Cedric 2013 年 3 月 31 日
If you really want to build n separate arrays, you will have to store them in a cell array, unless you want to dynamically generate variable names (which is almost never a good option). For example
n = 8 ;
m = 5 ;
c = cell(1, n) ;
for k = 1 : n
c{k} = zeros(1, m) ; % For 1xn arrays.
%c{k} = zeros(m) ; % For mxm arrays.
end
and then you can access arrays through cells form the cell array, e.g.
c{4}(3) = 9 ; % Set element 3 of array 4 to 9, if 1xm arrays.
c{4}(3,2) = 9 ; % Set element (3,2) of array 4 to 9, if mxm arrays.
However, if you are dealing with 1xn arrays, Image Analyst gave you the optimal solution.

Image Analyst
Image Analyst 2013 年 3 月 31 日
Like one of these?
zeroArray = zeros(m, n);
oneArray = ones(m, n);
anArray = value * ones(m, n);
  2 件のコメント
hala
hala 2013 年 3 月 31 日
no , i mean if n=5 i want to create 5 arrayes with size of m
Image Analyst
Image Analyst 2013 年 3 月 31 日
It's best to do it as an array, like I showed you. You don't want some number of separate arrays with different variable names. Please see the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F

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

カテゴリ

Help Center および File ExchangeComputer Vision Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by