Store user input data into matrix

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

 Respuesta aceptada

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato el 17 de Mayo de 2020
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

Más respuestas (0)

Categorías

Community Treasure Hunt

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

Start Hunting!

Translated by