using logic with units - can it be done?

3 次查看(过去 30 天)
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.

采纳的回答

James Tursa
James Tursa 2020-5-7
编辑:James Tursa 2020-5-7
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( ).

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by