how can i extract each element from excel and compare with a constant

1 回表示 (過去 30 日間)
NN
NN 2020 年 8 月 22 日
回答済み: Star Strider 2020 年 8 月 22 日
i have an excel file with date and elecricity price.I want to compare each price (which is hourly base) with a constant value,say a. how do i extract each element in that excel of price value and compare with a constant, and if that conditions is yes, i want to label it as another constant,say b ,if not i want to save/label it as say c.
how can i write the code using if else statement in matlab code

採用された回答

Star Strider
Star Strider 2020 年 8 月 22 日
I am not certain what you want.
Try this:
ElectricityPrice = randi(250, 50, 1); % Create Data
Constant = 42; % Create Constant
b = 1; % Define ‘b’
c = 2; % Define ‘c’
Lv = ElectricityPrice > Constant; % Logical Vector
ElectricityPrice(Lv,2) = b; % Define Second Column
ElectricityPrice(~Lv,2) = c; % Define Second Column
That sets the second column (to create a different vector, if that is what you want, is easily done) to either ‘a’ or ‘b’.
.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by