Concatenate strings and numbers
47 次查看(过去 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 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!