How to add a string to all member in matrix?

Example: I have:
a = [1 2 3; 4 5 6; 7 8 9]
I want have:
b = [s1 s2 s3; s4 s5 s6; s7 s8 s9]

4 comentarios

James Tursa
James Tursa el 9 de Jun. de 2015
Editada: James Tursa el 9 de Jun. de 2015
What is b supposed to be? A symbolic matrix? A cell array of strings? A string expression that you are going to use eval( ) with to get a matrix b using pre-existing variables s1, s2, etc? Or what?
anh ht
anh ht el 9 de Jun. de 2015
Editada: anh ht el 9 de Jun. de 2015
b is a symbolic matrix or anything matrix. I want display matrix:
s1 s2 s3
s4 s5 s6
s7 s8 s9
Stephen23
Stephen23 el 9 de Jun. de 2015
Editada: Stephen23 el 9 de Jun. de 2015
@anh ht: What is an "anything matrix"? Perhaps the terms are being used a little bit differently: instead of telling us what kind of matrix you want, tell us actually what you want to achieve with this. What are you actually trying to do?
@Stephen Cobeldick: Sorry. My English is bad. after calculation, I want display output matrix:
s1 s2 s3
s4 s5 s6
s7 s8 s9

Iniciar sesión para comentar.

 Respuesta aceptada

the cyclist
the cyclist el 9 de Jun. de 2015
Editada: the cyclist el 9 de Jun. de 2015
I have the same questions that James Tursa asked, but here is my best guess as to what you want:
b = cellfun(@(x)['s',num2str(x)],num2cell(a),'UniformOutput',false)

1 comentario

anh ht
anh ht el 9 de Jun. de 2015
Editada: anh ht el 9 de Jun. de 2015
Thanks. But I want:
s1 s2 s3
s4 s5 s6
s7 s8 s9
not:
's1' 's2' 's3'
's4' 's5' 's6'
's7' 's8' 's9'

Iniciar sesión para comentar.

Más respuestas (1)

James Tursa
James Tursa el 9 de Jun. de 2015
Editada: James Tursa el 9 de Jun. de 2015
For a symbolic matrix output, e.g.,
n = numel(a);
s = '[';
for k=1:n
e = ['s' num2str(a(k))];
eval(['syms ' e]);
s = [s ' ' e];
end
s = [s ']'];
b = reshape(eval(s),size(a));

Categorías

Más información sobre Operators and Elementary Operations en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 9 de Jun. de 2015

Comentada:

el 9 de Jun. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by