Store user input data into matrix
2 次查看(过去 30 天)
显示 更早的评论
Hello, I'm trying to store new user input data into matrix and export that data to excel, but I couldn't find the way to do it. Can anybody help me???
close all;
clear all;
clc;
n=2;
while(1)
filename='data';
A={'Vehicle model number','Vehicle purpose','Vehicle registration number','starting year of registration','ending year of registration', 'owner'};
fprintf(' *programme name* \n')
fprintf('---------------------------\n')
fprintf('1) car registration \n')
fprintf('0) close the programme \n')
fprintf('---------------------------\n')
m=input('enter the choice : ');
if m==1
fprintf(' *1) car registration \n')
fprintf('---------------------------\n')
number=input('- Vehicle information number :','s');
year=input('- starting year of registration(year) :');
period=input('- registration period(year) :');
owner=input('- owner :','s');
Anew={number(1:3),number(4),number(5:8),year,year+period,owner};
A(n,1)=num2cell(Anew(1,1));
A(n,2)=num2cell(Anew(1,2));
A(n,3)=num2cell(Anew(1,3));
A(n,4)=num2cell(Anew(1,4));
A(n,5)=num2cell(Anew(1,5));
A(n,6)=num2cell(Anew(1,6));
n=n+1;
end
if m==0
break;
end
xlswrite('data',A);
end
0 个评论
采纳的回答
Thiago Henrique Gomes Lobato
2020-5-17
Your loop position was wrong and you should save values as strings, not cells. This version of your code works:
n=2;
filename='data';
A={'Vehicle model number','Vehicle purpose','Vehicle registration number','starting year of registration','ending year of registration', 'owner'};
fprintf(' *programme name* \n')
fprintf('---------------------------\n')
while(1)
fprintf('1) car registration \n')
fprintf('0) close the programme \n')
fprintf('---------------------------\n')
m=input('enter the choice : ');
if m==1
fprintf(' *1) car registration \n')
fprintf('---------------------------\n')
number=input('- Vehicle information number :','s');
year=input('- starting year of registration(year) :');
period=input('- registration period(year) :');
owner=input('- owner :','s');
Anew={number(1:3),number(4),number(5:8),year,year+period,owner};
A(n,1)=(Anew(1,1));
A(n,2)=(Anew(1,2));
A(n,3)=(Anew(1,3));
A(n,4)=(Anew(1,4));
A(n,5)=(Anew(1,5));
A(n,6)=(Anew(1,6));
n=n+1;
end
if m==0
xlswrite('data',A);
break;
end
end
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!