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

1 view (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 22 Aug 2020
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’.
.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!