Reading Workspace variable into csv file

I got above 22 side bands output from 3D DWT, which are represented in the form of matrix. I need to read this into the csv file. Can anyone help me out???

6 个评论

you can always write data to csv or many types of other files. The question that is not clear here is how do you want them to be saved (displayed) in the csv. They are 3d matrix.
How can I write WT.dec{1, 1} into the csv file???
Presumably you need them in a csv file because another program needs to read them. What format does that other program require?
You misunderstand me. Your matrix is 3D. There are many ways to encode that information into a file that contains comma separated values. Some programs/formats require you to put the coordinates first, followed by the value, with one line per value.
You see the route that Mathworks has chose to display the data: page by page. You could do that as well, but is your program able to understand you mean 17x19x17 instead of 17x323?
Yes, another program requires in 17x323 format.

请先登录,再进行评论。

 采纳的回答

The most important thing to do first is to reshape the data to a 2D array. Then we can use the writematrix function as normal.
WT.dec{1,1}=rand(17,19,17);%generate random data
d=WT.dec{1, 1};%store in other variable for shorter syntax
%option 1: 17x323
d1=reshape(d,size(d,1),[]);
%option 2: 289x19
d2=mat2cell(d,size(d,1),size(d,2),ones(1,size(d,3)));
d2=cell2mat(d2(:));
filename='d1.csv';
writematrix(d1,filename)

8 个评论

For the above code, i got this error: Undefined function or variable 'writematrix'.
so i tried ,
WT.dec{1,1}=rand(17,19,17);%generate random data
d=WT.dec{1, 1};%store in other variable for shorter syntax
%option 1: 17x323
d1=reshape(d,size(d,1),[]);
%option 2: 289x19
d2=mat2cell(d,size(d,1),size(d,2),ones(1,size(d,3)));
d2=cell2mat(d2(:));
xlswrite('DWT.csv',d2);
The above code run successfully, mean while didn't run for d1(option 1).
Are you using an older release? The writematrix function was introduced in R2019a.
Do you mean the code now runs as it should? Or are you still having some issue?
Yes i am using older version. The issue is i am getting error for the option 1: 'The specified data range is invalid or too large to write to the specified file format.'
For option option 2 code run successfully.
Some software will cap the size of a line in a file to 1023 characters. If you have 323 columns in your data (as with option 1), that means each value can only take up 3 characters, which includes the comma. Apparently Matlab is smart enough to detect this as a potential issue. I would have argued for throwing a warning instead of an error, but that is just me.
But I'm glad to be of help. If you feel my answer helped you solve the issue, feel free to mark it as accepted answer.
Hey, after writing these matrix into csv file, when i open the file, it is showing that file is corrupted and the another program is not able to undertand that. So can plz suggest any thing for this???
What program concluded the file is corrupt? A text editor or your target software?
Machine learning classifier program.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Large Files and Big Data 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by