can i use linspace here??
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Matt Fig
am 4 Dez. 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.
Akzeptierte Antwort
Image Analyst
am 4 Dez. 2012
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 Kommentar
Walter Roberson
am 4 Dez. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!