Concatenate strings and numbers

조회 수: 109 (최근 30일)
Robert Demyanovich
Robert Demyanovich 2022년 3월 9일
편집: DGM 2022년 3월 9일
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]

채택된 답변

DGM
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
String1 = '10'
CoeffsRange = ["H2:K" String1] % [string char] -> string array
CoeffsRange = 1×2 string array
"H2:K" "10"
CoeffsRange = ['H2:K' String1] % [char char] -> char vector
CoeffsRange = 'H2:K10'
CoeffsRange = "H2:K" + String1 % string + char -> string
CoeffsRange = "H2:K10"
CoeffsRange = strcat("H2:K",String1) % or use strcat()
CoeffsRange = "H2:K10"

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by