MATLAB Answers

Plotting a logical function if a value is greater than 0

조회 수: 27(최근 30일)
Wesley Murar
Wesley Murar 16 Apr 2021 5:35
댓글: Walter Roberson 16 Apr 2021 10:00
I'm trying plot a logical input over the course of the time vector tor, where as long if the function is true, then I would plot a solid line, if false it wouldn't plot anything. I have 6 different inputs that I need to make the comparison for listed in the ordinal, but I don't know how to plot that logical value over the course "tor". Can anyone help?
if real(s1.*conj(s2))>0;
AG = true();
y = ordinal({'AG', 'BG', 'CG', 'AB', 'BC', 'CA'})


Matt J
Matt J 16 Apr 2021 6:17
Something like this?
y=double(AG); y(~AG)=nan;
xlim([min(tor),max(tor)]);xlabel 'tor', ylabel 'y'
  댓글 수: 2
Walter Roberson
Walter Roberson 16 Apr 2021 10:00
Yes, I was careful to arrange that the Y axes values would be those values.

댓글을 달려면 로그인하십시오.

Walter Roberson
Walter Roberson 16 Apr 2021 6:36
torvals = linspace(0,6);
ntor = length(torvals);
C = categorical(nan(ntor,1), (1:6),{'AB', 'BC', 'CA', 'AG', 'BG', 'CG'}, 'ordinal',true);
ABvals = C;
BCvals = C;
CAvals = C;
AGvals = C;
BGvals = C;
CGvals = C;
for toridx = 1 : ntor
tor = torvals(toridx);
%stuff here based on tor
if real(s1.*conj(s2))>0
AGvals(toridx) = 'AG';
h = plot(torvals, [ABvals, BCvals, CAvals, AGvals, BGvals, CGvals]);
h(4).Color = [0.5, 0, 0.5]; %purple


Community Treasure Hunt

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

Start Hunting!

Translated by