Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Subscripted assignment dimension mismatch.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Fabio Freschi
el 4 de Abr. de 2020
You can use repmat and create a char array
function bigstring = string_multiplication(str,N)
bigstring = repmat(str,N,1);
disp(bigstring);
end
1 comentario
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!