Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Subscripted assignment dimension mismatch.
2 ビュー (過去 30 日間)
古いコメントを表示
I am a beginner programmer, but feel like I am missing something pretty fundamental here.
I am trying to make a function that takes 2 variables:
- a string str
- an integer N
It should then make a 1xN matrix containing the input string at each index and output the matrix.
function bigstring = string_multiplication(str,N)
bigstring(1:N) = str;
disp(bigstring);
end
When I call the function in the command window, I get the following message:
>> string_multiplication('Name',5)
Subscripted assignment dimension mismatch.
Error in string_multiplication (line 8)
bigstring(1:N) = str;
I have also tried predefining 'bigstring = zeros(1,N)' and using a for loop and get similar results.
0 件のコメント
回答 (1 件)
Fabio Freschi
2020 年 4 月 4 日
You can use repmat and create a char array
function bigstring = string_multiplication(str,N)
bigstring = repmat(str,N,1);
disp(bigstring);
end
1 件のコメント
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!