why is my code not outputting to an excel file? Can someone fix this? I get Warning: Unable to write to Excel format, attempting to write file to CSV format.

조회 수: 11 (최근 30일)
Hi when i load in my feature mat file it transposes them then exports to an excel file. I made an exccel file and ran the code. but the file is not exported. why? please fix this. Thanks.Here is the warning i get:
Warning: Unable to write to Excel format, attempting to write file to CSV format.
> In xlswrite (line 196)
% Load the feature mat file
load('feature6.mat');
% Initialize the output struct with empty arrays
outStruct = struct('avgSize', zeros(36,1), 'profileCounts', zeros(36,1), ...
'zoneArea', zeros(36,1), 'totalArea', zeros(36,1), ...
'AvgMinFeret', zeros(36,1), 'AvgFeret', zeros(36,1));
% Loop through each feature struct and concatenate the arrays for each field
for i = 1:3
for j = 1:12
% Concatenate the jth element of the current field from the current struct
outStruct.avgSize((i-1)*12 + j) = features(i).avgSize(j);
outStruct.profileCounts((i-1)*12 + j) = features(i).profileCounts(j);
outStruct.zoneArea((i-1)*12 + j) = features(i).zoneArea(j);
outStruct.totalArea((i-1)*12 + j) = features(i).totalArea(j);
outStruct.AvgMinFeret((i-1)*12 + j) = features(i).AvgMinFeret(j);
outStruct.AvgFeret((i-1)*12 + j) = features(i).AvgFeret(j);
end
end
% Export the output struct to an Excel file
filename = 'outStruct.xlsx';
sheetname = 'Sheet1';
range = 'A1:F36';
fieldnames = {'avgSize', 'profileCounts', 'zoneArea', 'totalArea', 'AvgMinFeret', 'AvgFeret'};
% Write field names to the first row
xlswrite(filename, fieldnames, sheetname, 'A1:F1');
% Write data to the remaining rows
xlswrite(filename, [outStruct.avgSize, outStruct.profileCounts, outStruct.zoneArea, ...
outStruct.totalArea, outStruct.AvgMinFeret, outStruct.AvgFeret], ...
sheetname, range);
  댓글 수: 4
Cris LaPierre
Cris LaPierre 2023년 5월 5일
Just a side note of the message you will see at the top of the xlswrite documentation page:
xlswrite is not recommended. Use writetable, writematrix, or writecell instead. For more information, see Compatibility Considerations.
Chanille
Chanille 2023년 5월 5일
@Image Analyst Sorry about that! I have read the provided link, thanks. Also attached the mat file.
@Torsten i get: Warning: Unable to write to Excel format, attempting to write file to CSV format.
> In xlswrite (line 196)
@Cris LaPierre okay, I hope its that easy of a fix but in my previous experience it was not but thanks for the suggestion.

댓글을 달려면 로그인하십시오.

채택된 답변

Fangjun Jiang
Fangjun Jiang 2023년 5월 5일
In terms of xlswrite(), your code is fine. I've tried it and it creates the file. You might want to change range='A2:F37'.
Try a simple example to see if your Excel app is able to write Excel file.
xlswrite('MyExl.xlsx',magic(5));
winopen('MyExl.xlsx');
  댓글 수: 7
Chanille
Chanille 2023년 5월 8일
This was in windows/dell. It did not work for me in Mac correct but on dell I got the above error when I tried to open the excel windows

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by