I have created a GUI to take some data from user and save this input in EXCEL file, but every time when user inputs the data and hits submit button the data is overwritten.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I thought a logic that every time when user hit submit button, matlab should check for the empty row and and write data in that row. Please suggest some code for this. The code i have used is as follows, but it is not working. n=100; for j= 1:n if(Aj=='') xlswrite('test2.xlsx',data,Aj:Cj); else j=j+1; end
0 Kommentare
Antworten (2)
Dennis
am 13 Jul. 2018
Aj cannot work, you are hoping that MATLAB takes A (not a string, probably doesnt even exist) and j (a double) and put them together to form a string.
I am not sure what the loop and the if statement are supposed to do if you want to write your data via GUI i suggest you take a variable j and pass it to your callback to keep track of rowcount.
To make your actual code work you need to tell MATLAB what to do with A,C and j.
xlswrite('test2.xlsx',data,1,['A',num2str(j),':','C',num2str(j)])
6 Kommentare
Dennis
am 14 Jul. 2018
I don't have much time to test right now. This might work:
sizes = get(handles.size,'value');
switch sizes
case 1
msgbox('Select Size');
case 2
sizem = 'S';
case 3
sizem = 'M';
case 4
sizem = 'L';
case 5
sizem = 'XL';
case 6
sizem = 'XXL';
case 7
sizem = 'XXXL';
end
[~,~,raw]=xlsread('matlab.xlsx',sizem);
j=size(raw,1)+1;
data = {'Name','Registration Number','Contact Number','Room Number','Payment Mode','Payment ID','Size';names,regs,contacts,rooms, payment_mode,pids,sizem};
xlswrite('test2.xlsx',data,sizem,['A',num2str(j),':','C',num2str(j+1)])
msgbox('Details Successfully Submitted');
set(handles.name,'String','');
set(handles.reg,'String','');
set(handles.contact,'String','');
set(handles.room,'String','');
set(handles.pid,'String','');
set(handles.mode,'Value',1);
set(handles.size,'Value',1);
5 Kommentare
Dennis
am 19 Jul. 2018
Can you explain which part is not working? I just ran a simple test and for me it runs fine. You can use the paperclip button to attach files here.
for i=1:50
sizes=randi(7);
switch sizes
case 1
msgbox('Select Size');
case 2
sizem = 'S';
case 3
sizem = 'M';
case 4
sizem = 'L';
case 5
sizem = 'XL';
case 6
sizem = 'XXL';
case 7
sizem = 'XXXL';
end
try
[~,~,raw]=xlsread('matlab.xlsx',sizem);
j=size(raw,1)+1;
catch
data = {'Name','Registration Number','Contact Number','Room Number','Payment Mode','Payment ID','Size'};
xlswrite('matlab.xlsx',data,sizem,['A1:G1'])
j=2;
end
%some test data
names=char(63+j);
regs=char(63+j);
contacts=char(63+j);
rooms=char(63+j);
payment_mode=char(63+j);
pids=char(63+j);
data={names,regs,contacts,rooms, payment_mode,pids,sizem};
xlswrite('matlab.xlsx',data,sizem,['A',num2str(j),':','G',num2str(j)])
% msgbox('Details Successfully Submitted');
end
Siehe auch
Kategorien
Mehr zu Performance and Memory finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!