How to input name from the user using loop and simple input functions
Afficher commentaires plus anciens
I had this question in my exam where i had to ask the user to input n number of strings based on the value of n the user enters. and this is what i did. It works but there are some errors. I would like to know why does it occur and what does it mean ? and how to rectify them?
%the exact coding
clc
n=input('Enter value of n ');
a=[];
for k=1:n
a(k,:)=char(input('Input String ','s'));
end;
and the error message along with output :
Enter value of n 2
Input String defgh
Input String nvd
Subscripted assignment dimension mismatch.
Error in file (line 5)
a(k,:)=char(input('Input String ','s'));
Réponse acceptée
Plus de réponses (1)
KSSV
le 5 Juin 2017
n=input('Enter value of n ');
a=cell(n,1);
for k=1:n
a{k}=input('Input String ','s');
end
celldisp(a)
Catégories
En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!