can i use linspace here??

1 view (last 30 days)
YI Hsu Lo
YI Hsu Lo on 4 Dec 2012
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 Comment
Matt Fig
Matt Fig on 4 Dec 2012
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.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 4 Dec 2012
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 Comment
Walter Roberson
Walter Roberson on 4 Dec 2012
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.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!