How can I change a plot based on the file name?

1 vue (au cours des 30 derniers jours)
Alexis Brierty
Alexis Brierty le 16 Avr 2019
Commenté : Geoff Hayes le 17 Avr 2019
I want to plot some knee angles but I want to change the line style based on the file names.
An example of the file names would be:
BFND_W1. c3d
BFND_W1.plus3.c3d
BFND_W1.minus3.c3d
So for all fname's containing "plus", I want it to plot a "--" line and for all fname's containing "minus", I want to plot a ".." line.
I tried to use an if elseif code but just don't know how to code "if fname contains the word plus", "elseif fname contains minus".
Thanks in advance!!

Réponses (1)

Geoff Hayes
Geoff Hayes le 17 Avr 2019
Alexis - depending upon your version of MATLAB, you can use use either strfind or contains to determine if a substring exists within your filename. For example, the code
filename = 'BFND_W1.minus3.c3d';
linestyle = '-';
if ~isempty(strfind(filename, 'plus'))
linestyle = '--';
elseif ~isempty(strfind(filename, 'minus'))
linestyle = '-.';
end
% plot your data with the chosen LineStyle
plot(1:10,1:10,'LineStyle',linestyle);
might do what you want.
  1 commentaire
Geoff Hayes
Geoff Hayes le 17 Avr 2019
Alexis' answer moved here
Thanks! I'll give it a go

Connectez-vous pour commenter.

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