can i use linspace here??

13 ビュー (過去 30 日間)
YI Hsu Lo
YI Hsu Lo 2012 年 12 月 4 日
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
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
Image Analyst 2012 年 12 月 4 日
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
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 ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by