handling arrays of strings
Mostrar comentarios más antiguos
I want to create an array of strings in a manner that allows the strings to be easily changed, I would like something like this:
Signals = cellstr('Signals');
horzcat(Signals,...
'SignalName1',...
'SignalName2',...
'SignalName3',...
'SignalName4',...
'SignalName5', );
The problem is that horzcat merges the strings, is there a simple way to achieve this? James
4 comentarios
James Tursa
el 17 de Feb. de 2015
It is not clear what is the desired outcome? If you don't want a cell array of individual strings (as the above produces if you get rid of the final comma), then what do you want as an outcome?
per isakson
el 17 de Feb. de 2015
Editada: per isakson
el 17 de Feb. de 2015
- "create an array of strings"   is that cell array of strings?
- "Signals = cellstr('Signals')"   what's the intent with this line?
- "be easily changed"   is that easily easily edited in the editor?
James Holland
el 17 de Feb. de 2015
per isakson
el 17 de Feb. de 2015
Editada: per isakson
el 17 de Feb. de 2015
I often use this way to write cell arrays of strings in code. The string 'SignalName3' is commented out. It is easy to read and edit. Often I want a row to use in a for-loop:   for signal = Signals
Signals = {
'Signals'
'SignalName1'
'SignalName2'
... 'SignalName3'
'SignalName4'
'SignalName5'
};
Signals = transpose({
'Signals'
'SignalName1'
'SignalName2'
... 'SignalName3'
'SignalName4'
'SignalName5'
});
Respuestas (1)
pankhuri kasliwal
el 25 de Jun. de 2019
Editada: pankhuri kasliwal
el 25 de Jun. de 2019
Signals= cellstr('Signals');
Signals = [Signals, 'SignalName1'];
Signals = [Signals, 'SignalName2'];
This way it won't merge the strings all together, you will get all the strings in an array.
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!