Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

if an array like [.002 1.1103 0.665 .002]. how can i get [a b c a]?

1 visualización (últimos 30 días)
parthasarathi ghorai
parthasarathi ghorai el 23 de Abr. de 2015
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
if an array like [.002 1.1103 0.665 .002]. how can i get [a b c a]? i want to print .002=a 1.1103=b .665=c .002=a. how can i get this?

Respuestas (3)

James Tursa
James Tursa el 23 de Abr. de 2015
Not sure what you want. Maybe this?
myVector = [.002 1.1103 0.665 .002];
a = myVector(1);
b = myVector(2);
c = myVector(3);
  2 comentarios
parthasarathi ghorai
parthasarathi ghorai el 23 de Abr. de 2015
if a=.002 then how can i get .002=a?
Michael Haderlein
Michael Haderlein el 23 de Abr. de 2015
Could you please tell us what you mean? Do you want to print something on the screen or do you want to access an array? And what do you mean with "get .002=a"?

Michael Haderlein
Michael Haderlein el 23 de Abr. de 2015
Does the output need to be ".002" or is "0.002" also fine? If there must not be the leading zero, what kind of array do you have? I mean, the internal representation of ".002" is 0.002 if it's any kind of numerical value.
Also, do you always have the scheme a-b-c-a or could it also be a-b-c-d or a-b-b-b or whatever could be imagined?
Despite these unclear points, the answer could possibly just be
fprintf(1,'%1.3f=a %1.3f=b %1.3f=c %1.3f=a\n',myarray);

Thomas Koelen
Thomas Koelen el 23 de Abr. de 2015
You could make a cell that looks like this:
x =
[0.2000] 'a'
[0.3000] 'b'
[0.5000] 'c'
Then do this:
y=cell2mat(x(:,1))
y =
0.2000
0.3000
0.5000
now let's say you want to find the letter that corresponds to 0.2
index=find(y==0.2)
now you do:
x{index,2}
which gives:
ans =
a
hope this does what you desire!

Etiquetas

Aún no se han introducido etiquetas.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by