Store user input data into matrix

조회 수: 3 (최근 30일)
Yoobin Lee
Yoobin Lee 2020년 5월 17일
댓글: Yoobin Lee 2020년 5월 17일
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

채택된 답변

Thiago Henrique Gomes Lobato
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개)

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by