필터 지우기
필터 지우기

How to use For loop to the below data?

조회 수: 3 (최근 30일)
Haitham AL Satai
Haitham AL Satai 2023년 6월 5일
댓글: Mathieu NOE 2023년 6월 28일
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에서 Graphics Object Properties에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by