How to change the contents of an exported .mat file to an Excel file
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Samah EL QASSAH
am 19 Sep. 2017
Kommentiert: Samah EL QASSAH
am 19 Sep. 2017
Hi,
I wrote a code that converts two .mat files into Excel files from the selected selection of a list named Log. The code is as follows:
function Log_Callback(hObject, eventdata, handles)
g=get(handles.Log,'value')
if (g~=1)
x=get(handles.Log,'String');
y=get(handles.Log,'value');
f=x{y};
if(strcmp(f,'Exchange between FT0 and FT1 "Boolean"'))
set_param('MAJ','SimulationCommand','stop');
stop(handles.t);
set(handles.Stop,'BackgroundColor', 'red');
data=load('FT1Exchange(1).mat');
h=fieldnames(data);
for k=1:size(h,1)
xlswrite('testFT1.xlsx',data.(h{k}),h{k})
end
winopen testFT1.xlsx
elseif(strcmp(f,'Exchange between FT0 and FT1 "Double"'))
set_param('MAJ','SimulationCommand','stop');
stop(handles.t);
set(handles.Stop,'BackgroundColor', 'red');
data=load('FT1Exchange(2).mat');
h=fieldnames(data);
for k=1:size(h,1)
xlswrite('testFT11.xlsx',data.(h{k}),h{k})
end
winopen testFT11.xlsx
end;
end;
I have two questions:
1- The following code converts both .mat into two separate Excel files, how can I insert both .mat into two sheets of the same Excel file?
2- I get as a result the following table:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/167294/image.png)
How can I add a column at the beginning that includes the name of each line?
Thank you for your Help
0 Kommentare
Akzeptierte Antwort
Tim Berk
am 19 Sep. 2017
According to the documentation, you can write to excel using
xlswrite(filename,A,sheet,xlRange)
So that should give you everything you need (sheet and range).
This code creates an excel file that does this:
A = [0 1 0 1 0 1];
B = [1 1 1 0 0 0];
xlswrite('xls_file.xlsx',A,'sheet_A','B1')
xlswrite('xls_file.xlsx','A','sheet_A','A1')
xlswrite('xls_file.xlsx',B,'sheet_B','B1')
xlswrite('xls_file.xlsx','A','sheet_A','A1')
Let me know if that helps.
Cheers, Tim
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets 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!