can i use linspace here??

9 visualizaciones (últimos 30 días)
YI Hsu Lo
YI Hsu Lo el 4 de Dic. de 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 comentario
Matt Fig
Matt Fig el 4 de Dic. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 4 de Dic. de 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 comentario
Walter Roberson
Walter Roberson el 4 de Dic. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by