WTF... sorry folks, I might be a bit tired from coding. I took things from c and didn't pay attention to the fact that break; in matlab obviously leaves the switch case.
assign characters in a for loop combined with switch case and then merge to a long string
2 ビュー (過去 30 日間)
古いコメントを表示
Hi all!
I want to assign a string array with one column and many rows containing binary values to an alphabetical character. However, this alphabetical character array should be transposed. Thus, it has only one row and many columns. In the last step, i want to combine all these columns into one cell using strjoin().
bitstream = 120×1 string array
"00001"
"00010"
"00011"
"00000"
"00001"
"Error"
"00011"
...
if exist('bitstream','var') ~= 0 % if bitstream exist, get into
for idx = 1:size(bitstream,1)
switch bitstream(idx,1)
case "00000"
outputText(1, idx) = " ";
break;
case "00001"
outputText(1, idx) = "A";
break;
case "00010"
outputText(1, idx) = "B";
break;
case "00011"
outputText(1, idx) = "C";
break;
otherwise
outputText(1, idx) = "_";
end
end
outputDisplay(1,1:end) = strjoin(outputText)
end
The result should look like outputDisplay = "ABC A_C"
There is no error in my code, but it doesnt work and I couldn't figure out why... In most cases he jumps way to early out of the for loop. But it is not consistent...
outputText =
Columns 1 through 21
"A" "B" % 118 values should follow here!
Is a query of strings within a switch case query like case "00001" not possible? Should I use if, else if statements instead?
0 件のコメント
採用された回答
その他の回答 (1 件)
Walter Roberson
2021 年 5 月 10 日
strjoin() defaults to putting space between the parts. Use a second parameter of '' to not put in spaces.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!