Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

save image in loop in matlab

Status
Not open for further replies.

a_tek7

Banned
Joined
Feb 9, 2006
Messages
161
Helped
11
Reputation
22
Reaction score
2
Trophy points
1,298
Location
Bandar Abbas
Activity points
0
matlab save image

Hi all.How can I save several images in a for loop or while loop with different names in matlab?
tx in advance.
 

matlab save jpg

count=10;
while ff<896
for x=1:n
for y=1:m
for fr=round((ff/2)+1):round((ff/2)+500)
a=grges(y,x,fr);
f(1,a+1)=f(1,a+1)+1;
bkage(y,x)=max(f( : ));
end
f(1, : )=0;
end
end
toc
imwrite(a(count),'bkage','jpg');
count=count+1;
end
matlab:Index exceeds matrix dimensions
so what 's the problem with this ?
tx in advance
 

save image in matlab

while ff<896

What is modifying ff to prevent this from looping forever? Also, I assume that a, the output from 'grges' is a scalar? I don't seem to have this function.

Added after 3 minutes:

Is grges a 3-D matrix? Since this is the only matrix call you make, it is the only possible source of this error. Maybe instead of round, you mean floor?

I'm spitballing here, there's a lot of missing info
 

matlab save plot

oh, you're right. I 'm sorry I forgot it .
'ff' is frame number(double) and always>0 'grges'(240x320x897 uint8) is a 3d matrix and 'a' is a scaler can choose values between 0-255(uint8).
'bkage' (240x320 uint8)is a 2d matrix and f is a (1x256 unit8).
 

saving images in matlab

If 'ff' can be a value up to 895, then
round(ff/2+500) can be up to 948.

Since size(grges,3) = 897, you get an error when you plug in an index value greater than 897.

Possible fix?

- change to 'while ff < 795'. This will ensure that you only reference valid indexes

- change to 'round(ff/2+449)'. This changes the range you are analyzing, but again, ensures valid indexes.

- If this toroidal? You could make 898 wrap around back to 1, 899 back to 2, etc.

Let me know if I can offer anything else
 

matlab save plot as image

AndyECE said:
- change to 'while ff < 795'. This will ensure that you only reference valid indexes

- change to 'round(ff/2+449)'. This changes the range you are analyzing, but again, ensures valid indexes.

- If this toroidal? You could make 898 wrap around back to 1, 899 back to 2, etc.

Let me know if I can offer anything else
but i had to cover all frame this means all 897 frames.


while ff<795

for x=1:n
for y=1:m
for fr=round((ff/2)+1):round((ff/2)+449)
a=grayimages(y,x,fr);
f(1,a+1)=f(1,a+1)+1;
background_image(y,x)=max(f:) ));
end
f(1,: )=0;
end
end
ff=fr;

imwrite(a(count),'background_images','jpg');
count=count+1;
end

??? Index exceeds matrix dimensions.
 

save plot image matlab

Ok, ok I have found the problem. The error is in the line

imwrite(a(count),'background_images','jpg');

a is a 1x1 scalar, so referencing a(count) isn't defined. Maybe you mean to do something like:

a(count)=grayimages(y,x,fr);

This would make a into a (1xcount) vector. Keep me posted!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top