Won't update the second graph

2 views (last 30 days)
William
William on 6 Jun 2023
Commented: William on 6 Jun 2023
b1 = a1(a1 ~= 0);
b2 = a2(a2 ~= 0);
b3 = a3(a3 ~= 0);
b4 = a4(a4 ~= 0);
ind = ~ismissing(b1);
ind1 = ~ismissing(b3)
% load('nameoffile.mat','b1','b2','b3','b4')
%
% save("nameoffile.mat","b1","b2","b3","b4",'-append')
figure(2);
subplot(1,2,1);
drawnow
hAxes = gca;
hold(hAxes,"on");
xlabel('CSI Amp');
ylabel('Keyhole Amp Low Res');
%plot(hAxes,b1(ind),b2(ind));
scatter(b1(ind),b2(ind),'filled')
[R,p] = corrcoef(b1,b2);
R = R(2);
p = p(2);
title(['R =' num2str(R) ', p =' num2str(p)]);
hold(hAxes,"off");
subplot(1,2,2);
drawnow
gAxes = gca;
hold(gAxes,"on");
xlabel('CSI R2M Amp');
ylabel('Keyhole R2M Amp Low Res');
%plot(gAxes,b3(ind1),b4(ind1),'o');
scatter(b3(ind1),b4(ind1),'filled')
[R,p] = corrcoef(b3,b4);
R = R(2);
p = p(2);
title(['R =' num2str(R) ', p =' num2str(p)]);
hold(gAxes,"off");
So I am trying to make two graphs on one tab. The one on the left will work fine, but the one on the right won't work. This only happens for certain sets of data when there is a NaN in the selected set. I used the "ind = ~ismissing(b1);" part to get b2 to ignore the coresponding point. But for some reason it does not want to graph b3 or b4 despite having the variables update correctly. It really just wont plot at all. Any and all advice is welcomed, thanks in advance!
  6 Comments
the cyclist
the cyclist on 6 Jun 2023
FYI, to upload a MAT file with the data, you can use the paper clip icon in the INSERT section of the toolbar.

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 6 Jun 2023
But b1 does not contain any NaN values here, and is a 1x10 while b2 is a 1x12. Your code would work if b1 actually contained the 2 NaN values that appear to have been removed. See below.
% I've added 2 NaN values to b1
b1 = [8.4874 9.1870 10.7755 10.9003 11.570 16.4168 3.4914 4.6170 7.5933 3.89766 nan nan];
b2 = [11.6589 11.8874 24.9780 14.9634 12.3281 28.6672 12.1673 13.0639 27.7843 10.5510 15.2769 32.3900];
b3 = [0.0232 0.0272 0.0316 0.0373 0.0407 0.0398 0.2932 0.0574 0.0830 0.0439 0.0422 0.0419];
b4 = [0.0385 0.0389 0.0362 0.0371 0.0433 0.0388 0.0349 0.0412 0.0446 0.0333 0.0369 0.0403];
ind = ~ismissing(b1);
ind1 = ~ismissing(b3);
figure
subplot(1,2,1);
drawnow
hAxes = gca;
hold(hAxes,"on");
xlabel('CSI Amp');
ylabel('Keyhole Amp Low Res');
%plot(hAxes,b1(ind),b2(ind));
scatter(b1(ind),b2(ind),'filled')
[R,p] = corrcoef(b1,b2);
R = R(2);
p = p(2);
title(['R =' num2str(R) ', p =' num2str(p)]);
hold(hAxes,"off");
subplot(1,2,2);
drawnow
gAxes = gca;
hold(gAxes,"on");
xlabel('CSI R2M Amp');
ylabel('Keyhole R2M Amp Low Res');
%plot(gAxes,b3(ind1),b4(ind1),'o');
scatter(b3(ind1),b4(ind1),'filled')
[R,p] = corrcoef(b3,b4);
R = R(2);
p = p(2);
title(['R =' num2str(R) ', p =' num2str(p)]);
hold(gAxes,"off");
  1 Comment
William
William on 6 Jun 2023
Ok I see where I was going wrong. Thank you for explaining that to me! Hope you have a good rest of your day.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!