Borrar filtros
Borrar filtros

Info

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

How to change valuo of variable with for loop ?

1 visualización (últimos 30 días)
Muhammad Andi Yusran
Muhammad Andi Yusran el 5 de Mayo de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
I want to change my variable value. I have 204 value in my output variable. I want to change it to specified. if the value is 1, change to 'One'. if the value is 2, change to 'Two'. I try my code but the variable name wont looping. Please help me.
m = matfile('elm_output.mat');
output = m.output;
required = output(1:204);
for i = 1:length(required)
if required(i) == 1
lbl = 'One';
name = {lbl};
end
if required(i) == 2
lbl = 'Two';
name = {lbl};
end
end
  1 comentario
Stephen23
Stephen23 el 5 de Mayo de 2020
Editada: Stephen23 el 5 de Mayo de 2020
The MATLAB approach would be to use basic arrays and indexing, rather than loops and ifs:
C = {'one','two'};
name = C(required);

Respuestas (0)

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by