채택된 답변

Walter Roberson
Walter Roberson 2024년 8월 9일

0 개 추천

You cannot generally convert .mat file to excel.
You can potentially convert to excel under the special case that the .mat file contains exactly one variable, and the one variable is a scalar or vector or 2D numeric, or the one variable is a 2D cell array (each entry of which is empty or scalar numeric or character vector or scalar string), or the one variable is a struct array in which each field of the array is empty or scalar numeric or character vector or scalar string, or the variable is a table() object.
If the .mat file contains a single variable that is scalar or vector or 2D numeric, then extract the variable from the .mat file and writearray()
If the .mat file contains a single variable that is a 2D cell array, then extract the variable from the .mat file and writecell()
If the .mat file contains a single variable that is a table() object, then extract the variable from the .mat file and writetable()
If the .mat file contains a single variable that is a struct array, then extract the variable from the .mat file and struct2table() and writetable()
If the .mat file contains more than one variable, then the best you can do is somehow group all of the variables together and write out the result -- or to write out the individual variables as different sheets in the excel file.

댓글 수: 4

Alyaa
Alyaa 2024년 8월 10일
thank you Walter but I need to save my matrix as an excel file to use it in other app
Image Analyst
Image Analyst 2024년 8월 10일
Yes, we already understood that, and he gave you instructions for doing that. Note: if you don't need the mat file at all for any other reason, it would be simpler to just call writematrix or writecell to directly write your variables to the Excel file, rather than saving them out first to a mat file and then reading them back in and then calling writematrix or writecell.
If you have any more questions, and still can't figure it out, then attach your mat file and Excel file (what you would like it to look like) with the paperclip icon after you read this:
Walter Roberson
Walter Roberson 2024년 8월 10일
I could write out code that extracted variables one-by-one from the .mat file, and then examined the variable to determine how best to convert it to an excel sheet. But frankly, doing that would be a waste of my time, because you already know exactly what your .mat looks like and so you can directly implement one of the described steps without going through all of the cross-checks that would be necessary for the general case.
Alyaa
Alyaa 2024년 8월 13일
Thank you very much I figured out where my mistake was

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

추가 답변 (0개)

카테고리

태그

질문:

2024년 8월 9일

댓글:

2024년 8월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by