Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to save Parfor loop output in text file.

159 views
Skip to first unread message

Pallab Ghosh

unread,
Apr 9, 2010, 10:35:28 AM4/9/10
to
Hi All,
I am a new user of Parallel Computing Toolbox. Would you please help me to figure out how to save a matrix (generated from parfor loop) as a text file. Here is the example:

A = zeros(3, 3, 10);
parfor k = 1:10
A(:, :, k) = k*rand(3);
end

Now I want to save matrix "A" as a text file.

I used all the following format but nothing works:

'-ascii' 8-digit ASCII format.

'-ascii', '-tabs' Tab-delimited 8-digit ASCII format.

'-ascii', '-double' 16-digit ASCII format.

'-ascii', '-double', '-tabs' Tab-delimited 16-digit ASCII format.

I got the following error : "Warning: Attempt to write an unsupported data type to an ASCII file.Variable 'A' not written to file."

Thanks and Regards,
Pallab (Student).

C T

unread,
Apr 9, 2010, 12:40:19 PM4/9/10
to
"Pallab Ghosh" <karna....@gmail.com> wrote in message <hpndvg$pep$1...@fred.mathworks.com>...

The problem is not the parfor, but the 3D matrix. You are basically trying to save a 3D matrix to a text file which are not supported by matlab. The easiest thing is to change A back to 2D matrix. Like below:
As=reshape(A,3,30);
save -ascii 'As.txt' 'As'

Hassaan Mustafa

unread,
Oct 5, 2012, 8:03:07 AM10/5/12
to
Hello Sir, i am having a question regarding dlmwrite ... is it possible to use dlmwrite within a loop to save results in text file each time with new file name.

what i am doing is taking several thousands inputs , for which i used looping method, within loop, a file is taken as input and then apply some functions and bla bla stuff of DSP applied over it, and output comes which is stored in a variable called as "D" ... that output is in the form of "m x m" matrix (Square matrix) and i want to save that result in a txt file. and the loop goes on to the next input... can you tell me how to do so

to do it on a single file, without using loop, i am doing this in by this manner

img=imread(image.png);
%function here some long calculation which leads to results in a matrix called D
D=function_results;
dlmwrite("results.txt",D);

now that works fine for a single file without loop. Now can you give some guidelines regarding saving within loop, Like

- loop starts, (I've done this)
- read the file, (I've done this)
- apply the function, (I've done this)
- store results in variable "D" (I've done this)
- that result saves in text file whose name is the same name of the input file but extension be text ( not able to solve this riddle)
- display the result (I've done this)
- go to next file (I've done this)

Thanking in regards.

P.S. I've tried save and fprintf, but i am not able to achieve the desired results.
0 new messages