필터 지우기
필터 지우기

Can I run a loop with image variables that have different dimensions?

조회 수: 2 (최근 30일)
Apologies if there is an obvious answer I'm missing.
I've got images stored as variables, but they've got different dimensions.
I've got this function to calculate the average RGB value of each image:
mean(reshape(I1, [], 3))
But I don't know how to make a loop that will run through each variable. I've tried to make it a list like this
a = [I1 I2 I3 I4 I5 I6 I7 I8]
But the dimensions are not the same, and it would be ideal if I did not have to edit the images further. Any help, or do I need to resize?

채택된 답변

Matt Macaulay
Matt Macaulay 2018년 4월 24일
Make a cell of the images and loop through the cell:
a = {I1 I2 I3 I4 I5 I6 I7 I8};
n = length(a);
for i = 1:n
% Do some stuff
end
  댓글 수: 2
Jamil Wanis
Jamil Wanis 2018년 4월 26일
a = {I1 I2 I3 I4 I5 I6 I7 I8};
n = length(a);
for i = 1:n
mean(reshape(i, [], 3))
end
I'm getting this error: Product of known dimensions, 3, not divisible into total number of elements, 1.
It is registering the i variable as 1:8, but how do I refer to the variables in the cell using i? Thank you for the help
Jamil Wanis
Jamil Wanis 2018년 4월 26일
Actually I believe I've gotten it using
a = {I1 I2 I3 I4 I5 I6 I7 I8};
n = length(a);
for i = 1:n
mean(reshape(a{1,i}, [], 3))
end
Is this the most effective way? Thank you for the solution!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품

Community Treasure Hunt

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

Start Hunting!

Translated by