Borrar filtros
Borrar filtros

Info

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

i need help for string code

1 visualización (últimos 30 días)
phayu
phayu el 14 de Feb. de 2014
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
this is my code...
clear all
a={'a1' 'a2'};
when i put
a1=1;,a2=2;
disp(a)
result
a = 'a1' 'a2'
but i want my result is
= '1' '2'
what is a problem in my code?
thx for your help

Respuestas (2)

Wayne King
Wayne King el 14 de Feb. de 2014
When you write
a1 = 1;
a2 = 2;
You are creating two new variables with values 1 and 2.
What about:
vals = {'1','2'};
newa = strrep(a,a,vals);
disp(newa)

Jos (10584)
Jos (10584) el 14 de Feb. de 2014
The following might give some insight
a1 = 1 ; a2 = 2 ; A = {a1 a2} ; % declaration
disp(A)
A{1} = 10 ; % change the contents (hidden by the semi-colon)
disp(A)
a1 = 3 % does not change the contents of A
disp(A)
  2 comentarios
phayu
phayu el 15 de Feb. de 2014
sorry for unclear of my question,
i want it show
a='a1' 'a2'
and when i input
a1=1 a2=2
it show
a= '1' '2'
so much thx !
Jos (10584)
Jos (10584) el 15 de Feb. de 2014
You've lost me … Do you understand the concepts of variables, strings, doubles and cells? If not, take a look at the documentation.

La pregunta está cerrada.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by