can i use linspace here??
13 ビュー (過去 30 日間)
古いコメントを表示
i have 11 numbers that is showed in the form below
e1=(-5)+PP(1:2).*(-5);
e2=(-5)+PP(1:2).*(-5.5);
e3=(-5)+PP(1:2).*(-6);
e4=(-5)+PP(1:2).*(-6.5);
e5=(-5)+PP(1:2).*(-7);
e6=(-5)+PP(1:2).*(-7.5);
e7=(-5)+PP(1:2).*(-8);
...............
size(PP(1:2))=2 1
i would like to type them in a simpler form, and i just transform them into
RR=linspace(-5,-10,11);
for rr=1:11;
eval(['e',num2str(rr),'=(-5)+PP(1:2).*RR']);
end;
but it's not work, how can i deal with this problem? could someone help me PLEASE!!!!!!!!!!!!!!
1 件のコメント
Matt Fig
2012 年 12 月 4 日
As IA pointed out, Don't program in MATLAB this way! Learn to use MATLAB the way it was designed to be used. Rather than making many separate variables, make one variable that holds all the same information. For this task you can use an N-D array, a structure or a cell array.
採用された回答
Image Analyst
2012 年 12 月 4 日
The answer is in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
You should do an array instead with no for loop and no separate variables:
e = -5 + linspace(-5, -8, 7);
but I don't know what PP is.
1 件のコメント
Walter Roberson
2012 年 12 月 4 日
e = -5 + @bsxfun(@times, PP(1:2), linspace(-5, -8, 7));
then your e6 (for example) would be e(:,6)
Note: this code relies on P(1:2) being a column vector.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!