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 件のコメント

Peng Li
Peng Li 2020 年 4 月 2 日
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.
Mehul Jain
Mehul Jain 2020 年 4 月 2 日
How can I write WT.dec{1, 1} into the csv file???
Rik
Rik 2020 年 4 月 2 日
Presumably you need them in a csv file because another program needs to read them. What format does that other program require?
Mehul Jain
Mehul Jain 2020 年 4 月 2 日
CSV format.
Rik
Rik 2020 年 4 月 2 日
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?
Mehul Jain
Mehul Jain 2020 年 4 月 2 日
Yes, another program requires in 17x323 format.

サインインしてコメントする。

 採用された回答

Rik
Rik 2020 年 4 月 2 日

1 投票

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 件のコメント

Mehul Jain
Mehul Jain 2020 年 4 月 2 日
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).
Rik
Rik 2020 年 4 月 2 日
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?
Mehul Jain
Mehul Jain 2020 年 4 月 3 日
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.
Rik
Rik 2020 年 4 月 3 日
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.
Mehul Jain
Mehul Jain 2020 年 4 月 3 日
Thank You so much.
Mehul Jain
Mehul Jain 2020 年 4 月 5 日
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???
Rik
Rik 2020 年 4 月 5 日
What program concluded the file is corrupt? A text editor or your target software?
Mehul Jain
Mehul Jain 2020 年 4 月 6 日
Machine learning classifier program.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLarge Files and Big Data についてさらに検索

タグ

質問済み:

2020 年 4 月 2 日

コメント済み:

2020 年 4 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by