how to pass the matrix value outside the loop
    6 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
I need to pass the matrix value of 'xd' outside the loop.
% display all the blocks.
plotIndex = 1;
numPlotsR = size(ca, 1); 
numPlotsC = size(ca, 2); 
for r = 1 : numPlotsR
  for c = 1 : numPlotsC
    subplot(numPlotsR, numPlotsC, plotIndex);
    rgbBlock = ca{r,c};
    %find the different pixel intensity
    maxi= max(rgbBlock(:))
    mini= min(rgbBlock(:))
    diff = maxi - mini
    if diff >= 150
      fprintf('Hard Region\n')
      n = 4;                   % Decomposition Level
      w = 'db4'            
      x = rgbBlock;
      [c l] = wavedec2(x,n,w); % Multilevel 2-D wavelet decomposition.
      opt = 'gbl'; % Global threshold
      thr = 20;    % Threshold
      sorh = 'h';  % Hard thresholding
      keepapp = 1; % Approximation coefficients cannot be thresholded
      [xd,cxd,lxd,perf0,perfl2] = wdencmp(opt,c,l,w,n,thr,sorh,keepapp);
      image(xd)    % xd is a matrix, I want to pass the ...
                    'xd' value out from this loop
    else if diff < 150
      fprintf('soft Region\n')
    else
      fprintf('Out of Region\n')
    end
  end
  [rowsB columnsB numberOfColorBandsB] = size(rgbBlock);
  plotIndex = plotIndex + 1;
end
TQ friend... :)
0 Kommentare
Antworten (1)
  Pratik
      
 am 12 Dez. 2024
        Hi Nik,
It is my understanding that you want to use the value of variable 'xd' outside of the for loop as well.
For now, variable's scope is defined inside the for loop hence accessing outside the loop will not be possible. To access the value of 'xd' it can be defined outside of the for loop. Please note that after the for loop ends 'xd' will have the latest value.
I hope this helps!
0 Kommentare
Siehe auch
Kategorien
				Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!