Numerical cell value changes to random symbols when using strcat - help needed
显示 更早的评论
I have a short bit of code assigning test numbers to variable names. I have a variable (testno) as cell type with the test number 1 - 54, when I try to join this with another cell type array of the same size (frequency) the numerical values in testno turn to random symbols.
I can't seem to find a reason why, I'm realively new to Matlab so chances are I'm not doing this right.
Sample code below:
>n1 = 54;
>testno = [1:54]
>testno = num2cell(testno.');
>testvariable = strcat(frequency, testno);
frequency is a celll type with 50Hz repeated 54 times in a single column.
I have also tried concatnenating tesno with 'T' and the same happens.
testvariable ends up like below but with more symbols this text editor can't show.
'50Hz'
'50Hz'
'50Hz'
'50Hz'
'50Hz'
'50Hz'
'50Hz'
'50Hz'
'50Hz '
'50Hz'
'50Hz'
'50Hz'
Any help is much appreciated!
Thanks,
Ben
采纳的回答
更多回答(1 个)
ES
2019-10-7
Since your testno is numeric, the when you do strcat, the number is converted to a character.
What you want is that number to be converted to string (use: num2str). Use
testno = num2cell(num2str(testno.'))
类别
在 帮助中心 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!