From: dale on
Hello,

When i use a for loop for to print out my arrays it overwrites in the textfile.
My code is below.
Can any of you guys help

dale.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc; clear all;
Rs1 = [ 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 1 0;
0 0 0 0 0 0 0 0 0 0 1 0;
0 0 0 0 0 0 0 0 0 1 1 0;
0 0 0 0 0 0 0 0 0 1 1 0;
0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 2 2 2 2 0 0;
0 3 3 3 0 0 2 2 2 2 2 0;
0 3 3 3 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0]


STATS = regionprops(Rs1, 'PixelList' )

fv=struct2cell(STATS)

[arbitary,num_of_regions] = size(fv)



% cc = fv{num_of_regions}

for i = 1:num_of_regions
prints = fv{i}
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
From: dpb on
dale wrote:
....
> When i use a for loop for to print out my arrays it overwrites in the
> textfile.
....
> for i = 1:num_of_regions
> prints = fv{i}
> end
....

I don't see any _files_ in sight; all the code listed will do is store
and since there's no echo-suppressing ";" termination display the value
at the console window. Of course, if that is the point there's also no
need for the assignment statement at all (nor the loop for that matter,
of course).

So, rather than do anything else specific to the question as posed I'll
ask for clarification of what is really wanted...

--
From: dale on
I would like the following in a textfile:

2,9
2,10
3,9
3,10
4,9
4,10
10,5
10,6
11,3
11,4
11,5
11,6
7,8
7,9
8,8
8,9
9,8
9,9
10,8
10,9
11,9

But instead, my textfile looks like the following:

2,9
2,10
3,9
3,10
4,9
4,10

So essentially since my output iin matlab looks like:
prints =

10 5
10 6
11 3
11 4
11 5
11 6


prints =

7 8
7 9
8 8
8 9
9 8
9 9
10 8
10 9
11 9


prints =

2 9
2 10
3 9
3 10
4 9
4 10

But i want :

prints =

10 5
10 6
11 3
11 4
11 5
11 6
7 8
7 9
8 8
8 9
9 8
9 9
10 8
10 9
11 9
2 9
2 10
3 9
3 10
4 9
4 10

Hope i am clearer now.
thanks
dale
From: dale on
guys,

all i am trying to ask is a basic way to kind of concatentate my matrix each time the for loop iterates.

it's urgent .any suggestion welcome

thanks

dale
From: dpb on
dale wrote:
> guys,
>
> all i am trying to ask is a basic way to kind of concatentate my matrix
> each time the for loop iterates.
>
> it's urgent .any suggestion welcome
....

chill, dood... :)

You had a counted loop so you know the size...hence, for efficiency
preallocate.

yournewarray = zeros(maxloopcount,1);
for idx = 1:maxloopcount
yournewarray(idx) = yourfunct(idx);
end

IIRC, you had a loop index of "i" in original post; don't do that as "i"
and "j" are functions in Matlab which return the complex i and
overloading them w/ a scalar index variable can lead to confusion if one
needs complex.

Also, of course, the above assignment to an array could (assuming the
function is vectorized as are most Matlab builtin functions) simply be
written as

yournewarray = yourfunct(1:maxloopcount);

This again assumes the RHS is aware of what to do w/ a vector.

And, this request again has nothing to do w/ any file at all so if there
is a need for that isn't clear from the questions posed

doc iofun

and particularly

doc fopen
doc fwrite

and friends. And, of course, the "Getting Started" section on file
input/output.

--