Concatenate strings and numbers
111 ビュー (過去 30 日間)
古いコメントを表示
I'm using the following code to try and create a "Range" for importing an excel spreadsheet into MATLAB. Instead of getting a single string, I am getting a 1x2 string for CoeffsRange. MaxRows is the number of rows in the Excel spreadsheet that contain data. Here's the code
String1=num2str(MaxRows)
CoeffsRange = ["H2:K" String1]
0 件のコメント
採用された回答
DGM
2022 年 3 月 9 日
編集済み: DGM
2022 年 3 月 9 日
Strings and chars are different. Take care in how you combine them.
MaxRows = 10;
String1 = num2str(MaxRows) % a char vector
CoeffsRange = ["H2:K" String1] % [string char] -> string array
CoeffsRange = ['H2:K' String1] % [char char] -> char vector
CoeffsRange = "H2:K" + String1 % string + char -> string
CoeffsRange = strcat("H2:K",String1) % or use strcat()
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!