필터 지우기
필터 지우기

How to insert row by row data to excel?

조회 수: 3 (최근 30일)
kasi visalakshi korlepara
kasi visalakshi korlepara 2015년 2월 15일
댓글: Image Analyst 2015년 2월 15일
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);

답변 (1개)

Geoff Hayes
Geoff Hayes 2015년 2월 15일
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.

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by