how can i extract each element from excel and compare with a constant
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!