Plotting a logical function if a value is greater than 0

17 vues (au cours des 30 derniers jours)
Wesley Murar
Wesley Murar le 16 Avr 2021
Commenté : Walter Roberson le 16 Avr 2021
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();
figure
plot(tor,AG)
y = ordinal({'AG', 'BG', 'CG', 'AB', 'BC', 'CA'})
end
Thanks

Réponses (2)

Matt J
Matt J le 16 Avr 2021
Something like this?
tor=1:10;
AG=tor>5;
y=double(AG); y(~AG)=nan;
h=plot(tor,y);
xlim([min(tor),max(tor)]);xlabel 'tor', ylabel 'y'
  2 commentaires
Wesley Murar
Wesley Murar le 16 Avr 2021
I need the y-axis to be the following values:
AG, BG, CG, AB, BC, and CA
Then if real(s1.*s2(conj)) > 0, then plot that with a solid line for the respective y-axis variable as shown in the picture.
Walter Roberson
Walter Roberson le 16 Avr 2021
Yes, I was careful to arrange that the Y axes values would be those values.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 16 Avr 2021
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';
end
end
h = plot(torvals, [ABvals, BCvals, CAvals, AGvals, BGvals, CGvals]);
h(4).Color = [0.5, 0, 0.5]; %purple

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by