Small Problem with 'if' statement and array index

2 vues (au cours des 30 derniers jours)
Dimitris M
Dimitris M le 29 Avr 2012
Hello
I have a rather simple problem that I can not overcome. The problem I am facing is that I have an 'if' statement that I want to be executed only for one line of a matrix array (cell array).
I tried something like this, but doesn't work
if Seg_Out_1{1,:}==true .....
This one gives me an error 'Too many Input Arguments'. Is this the right approach, or should I do something complete different ???
Thank you in advance very much !

Réponses (4)

Andrei Bobrov
Andrei Bobrov le 29 Avr 2012
if isequal(Seg_Out_1(1,:),otherCellArray)

Wayne King
Wayne King le 29 Avr 2012
This is a matrix as the first element of a cell array?
If so (and if by line you mean row), then you want to address that by Seg_out{1}(1,:)
Seg_out = cell(2,1);
Seg_out{1} = ones(2,2);
if (Seg_out{1}(1,:) == [1 1])
% or isequal(Seg_out{1}(1,:),[1 1])
disp('true');
else
disp('false');
end

Dimitris M
Dimitris M le 29 Avr 2012
Maybe I asked the question wrongly, let me be more precise.
I have a cell array containing image arrays in every one of its locations.
I want to give specific name to every image. All the images within the same row should have the same name (almost). So I am trying to create 'if' statements for accessing every row.
A small example of my non-working code
if Seg_Out_1{1,:}==true;
% Changing name of the exporting image tif file
Exp_Name_1 ='Seg_%d_Img-Diffused_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d.tif';
% Export Image command
imwrite(Seg_Out_1{1,Num_Seg},[ImageExpDir,sprintf(Exp_Name_1,Num_Seg,a,b,c,d,e,f,g,h,i,j,k)],'tif');
end
if Seg_Out_1{2,:}==true;
Exp_Name_2 ='Seg_%d_Img-Edgefunction_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d.tif';
% Export Image command
imwrite(Seg_Out_1{2,Num_Seg},[ImageExpDir,sprintf(Exp_Name_2,Num_Seg,a,b,c,d,e,f,g,h,i,j,k)],'tif');
end

Dimitris M
Dimitris M le 29 Avr 2012
I found a way to do it !
if isequal(Seg_Out_1{1,Num_Seg},Seg_Out_1{1,Num_Seg});
...
...
...
...
...
end
if isequal(Seg_Out_1{2,Num_Seg},Seg_Out_1{2,Num_Seg});
...
...
...
...
end

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by