How to use For loop to the below data?

1 次查看(过去 30 天)
I have 15 cells as shown below:
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?

采纳的回答

Mathieu NOE
Mathieu NOE 2023-6-5
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Descriptive Statistics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by