Effacer les filtres
Effacer les filtres

using logic with units - can it be done?

1 vue (au cours des 30 derniers jours)
Justin Bell
Justin Bell le 7 Mai 2020
Modifié(e) : James Tursa le 7 Mai 2020
I have a timetable of data which I have used the properties attribute to assign units to the variables (I'm sure I've done this wrong, but it seems to work for my otherneeds).
dataTable.Properties.VariableUnits = {'C','m/s','degrees','w/m^2','num','num','season'};
my question is when feeding data into functions is there a way to combine logic and units? I was looking for something along the lines of
if (data.units == 'm/s')
%append "Wind Speed" on to chart titles
else
%some other action
end
mainly I am performing the same calculation on different variables and want it to determine the labels to use on the plots without me manually passing it into the function calls. This will make it more flexible for changes and sharing my code between a few different sets of algorithms I need to run. Rather than hope to catch things with find and replace, I can set the correct units on data import and everything would "just work". I'm on 2019a, but I can upgrade if it will solve my issue.

Réponse acceptée

James Tursa
James Tursa le 7 Mai 2020
Modifié(e) : James Tursa le 7 Mai 2020
Don't use == for single quoted strings, since that will do an element-by-element calculation. So this
if (data.units == 'm/s')
needs to change. E.g.,
if (isequal(data.units,'m/s'))
or maybe use one of the string comparison functions, strcmp( ) or strcmpi( ).

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by