Azzera filtri
Azzera filtri

using logic with units - can it be done?

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

James Tursa
James Tursa il 7 Mag 2020
Modificato: James Tursa il 7 Mag 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( ).

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by