Numerical cell value changes to random symbols when using strcat - help needed
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (1)
ES
il 7 Ott 2019
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.'))
Categorie
Scopri di più su Characters and Strings in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!