Store user input data into matrix

2 ビュー (過去 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
  1 件のコメント
Yoobin Lee
Yoobin Lee 2020 年 5 月 17 日
thanks, it worked! :D

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeometric 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