フィルターのクリア

using logic with units - can it be done?

1 回表示 (過去 30 日間)
Justin Bell
Justin Bell 2020 年 5 月 7 日
編集済み: James Tursa 2020 年 5 月 7 日
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 Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by