How to use For loop to the below data?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Haitham AL Satai
am 5 Jun. 2023
Kommentiert: Mathieu NOE
am 28 Jun. 2023
I have 15 cells as shown below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1403189/image.jpeg)
I would like to plot their data. As shown below, I drew the data for the first two cells
% First case
figure
A = berMap(1,1);
% caculate the coverage area
isSmaller = cellfun( @(X) X < 0.0038, A(:), 'UniformOutput', false);
numSmaller = sum(sum(isSmaller{:} == 1));
% Draw BerMap
Coverage_area = (numSmaller/(41*41))*400; %Important
surf(X_r,Y_r,A{1,1})
colorbar
view(0,90)
xlabel('X (m)');
ylabel('Y (m)');
zlabel('BER');
axis([-L/2 L/2 -W/2 W/2 min(min(A{1,1})) max(max(A{1,1}))]);
grid on;
hold on;
% Plotting the FEC
Amat = cell2mat(berMap(1,1));
Amat(Amat > 0.0038) = 0;
Amatrix = Amat;
Amatrix(Amat == 0) = nan;
hSurface = surf(X_r,Y_r,Amatrix);
set(hSurface, 'EdgeColor',[1 1 1],'FaceColor',[1 1 1]);
view(0,90)
%Second Case
figure
B = berMap(2,1);
% caculate the coverage area
isSmaller1 = cellfun( @(X) X < 0.0038, B(:), 'UniformOutput', false);
numSmaller1 = sum(sum(isSmaller1{:} == 1));
% Draw BerMap
Coverage_area1 = (numSmaller1/(41*41))*400; %Importrant
surf(X_r,Y_r,B{1,1})
colorbar
view(0,90)
xlabel('X (m)');
ylabel('Y (m)');
zlabel('BER');
axis([-L/2 L/2 -W/2 W/2 min(min(B{1,1})) max(max(B{1,1}))]);
grid on;
hold on;
% Plotting the FEC
Amat1 = cell2mat(berMap(2,1));
Amat1(Amat1 > 0.0038) = 0;
Amatrix1 = Amat1;
Amatrix1(Amat1 == 0) = nan;
hSurface1 = surf(X_r,Y_r,Amatrix1);
set(hSurface1, 'EdgeColor',[1 1 1],'FaceColor',[1 1 1]);
view(0,90)
I would like to use a for loop in order to draw them without writing the above codes for 15 time.
Any assistance,please?
0 Kommentare
Akzeptierte Antwort
Mathieu NOE
am 5 Jun. 2023
here you are my friend :
% main loop
for k = 1:numel(berMap)
figure
A = berMap(k);
% caculate the coverage area
isSmaller = cellfun( @(X) X < 0.0038, A(:), 'UniformOutput', false);
numSmaller = sum(sum(isSmaller{:} == 1));
% Draw BerMap
Coverage_area = (numSmaller/(41*41))*400; %Important
Amat = A{1,1};
surf(X_r,Y_r,Amat)
colorbar
view(0,90)
xlabel('X (m)');
ylabel('Y (m)');
zlabel('BER');
axis([-L/2 L/2 -W/2 W/2 min(Amat,[],'all') max(Amat,[],'all')]);
grid on;
hold on;
% Plotting the FEC
Amat(Amat > 0.0038) = 0;
Amatrix = Amat;
Amatrix(Amat == 0) = nan;
hSurface = surf(X_r,Y_r,Amatrix);
set(hSurface, 'EdgeColor',[1 1 1],'FaceColor',[1 1 1]);
view(0,90)
end
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Object Properties 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!