Filter löschen
Filter löschen

using logic with units - can it be done?

1 Ansicht (letzte 30 Tage)
Justin Bell
Justin Bell am 7 Mai 2020
Bearbeitet: James Tursa am 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.

Akzeptierte Antwort

James Tursa
James Tursa am 7 Mai 2020
Bearbeitet: James Tursa am 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( ).

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by