I have variable A containing several string array as follows :
'0' '->' '2' '1.000000' '1.000200' 'A-MPDU' '1.000000'
'0' 'NO' 'NaN' '1.000270' '1.000570' 'BACKOFF' 'NaN'
I want to make those strings into one string form like this :
'0 -> 2 1.000000 1.000200 A-MPDU 1.000000'
'0 NO NaN 1.000270 1.000570 BACKOFF NaN'
How to realize this using matlab?
Presumably A
is a cell array, so you could convert one row of it to an array of characters with
char(cellfun(@(x)[x ' ']',C(1,:),'UniformOutput',false))'
Note that we use cellfun
to apply our anonymous function to each character array (element) of the cell array. The function appends a space to the character array (i.e. '0' becomes '0 '), and then we transpose this result to get a column. We do this for each element so that the final result is a column of characters which we do one final transpose on to get the string.
For example
>> char(cellfun(@(x)[x ' ']',C(1,:),'UniformOutput',false))'
ans =
0 -> 2 1.000000 1.000200 A-MPDU 1.000000
>> char(cellfun(@(x)[x ' ']',C(2,:),'UniformOutput',false))'
ans =
0 NO NaN 1.000270 1.000570 BACKOFF NaN
Try the above and see what happens!
Method 1:
If you want to combine two strings together,use strcat
Example:
str = strcat('Good', 'morning')
str =
Goodmorning
But you need spaces in between strings:
So you have to change your strings to something like: '0 ' '-> ' '2 '
to get the string that you want.
Another method:
a='aaaa';
b='bb';
c=sprintf('%s %s',a,b);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With