Borrar filtros
Borrar filtros

How to insert row by row data to excel?

3 visualizaciones (últimos 30 días)
kasi visalakshi korlepara
kasi visalakshi korlepara el 15 de Feb. de 2015
Comentada: Image Analyst el 15 de Feb. de 2015
I am using five edit text boxes so, the data entered in the text boxes should go to excel every time by pressing the push button the code iam using is
fid=fopen('in.csv','w')
global a1
a1=get(handles.edit1,'string');
b1=str2double(a1);
disp(b1)
global a2
a2=get(handles.edit2,'string');
b2=str2double(a2);
disp(b2)
global a3
a3=get(handles.edit3,'string');
b3=str2double(a3);
disp(b3)
global a4
a4=get(handles.edit4,'string');
b4=str2double(a4);
disp(b4)
global a5
a5=get(handles.edit5,'string');
b5=str2double(a5);
disp(b5)
global a6
a6=get(handles.edit6,'string');
b6=str2double(a6);
disp(b6)
A=[b1,b2,b3,b4,b5,b6];
fprintf(fid,'%f',A(:,:));
fprintf(fid,'\r \n');
fclose(fid);

Respuestas (1)

Geoff Hayes
Geoff Hayes el 15 de Feb. de 2015
Kasi - it appears that you are just writing your data to a comma-separated file and not an Excel file. Is this intentional? If the idea is to just write out a new row to your file every time that the user presses a button in your GUI, and so you don't want to overwrite the data that you had there already, then you should open your file for appending as
fid=fopen('in.csv','a+')
Declaring variables as global is unnecessary (unless you need to access this data elsewhere). When it comes to writing the data to file, just do
A=[b1,b2,b3,b4,b5,b6];
fprintf(fid,'%f\t',A(:,:));
fprintf(fid,'\n');
fclose(fid);
We use the \t to separate each column of data with a tab. Try the above and see if it does what you expect.

Categorías

Más información sobre Data Import from MATLAB en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by