How to write for or while loop along with indexing?
Afficher commentaires plus anciens
Hello Sirs
May I ask your guidance for my study please?
There are three data in my problem (1) months and (2) Demand (3) X for several years.
I need to specify the first X value as SWA and second X value as EWA and third value as HF.
In this sample excel file 2 years data is given. Thus, there will be two SWA, two EWA and two HF.
Then, I need to mulitply the every 12 months Demand data with specific SWA, EWA and HF.
First SWA value (0.0319) should mulitply the demand 1:12 and second SWA value (0.9873) should multiply the demand 13:24 and so on.
First EWA (0.5272) should mulitply with constant value K= 1000 and plus with demand 1:12. Similarly, second EWA (0.0028) should multiply with K=1000 and plus the demand data from 13:24.
%input
clear all;
data=xlsread('data.xlsx');
demand=data(1:24,2);
x=data(1:6,3);
K=1000;
% I used incrementing by 3 to get the SWA , EWA and HF index and value.
SWA_idx=[1:3:6]';SWA_x=x(SWA_idx);
EWA_idx=[2:3:6];EWAx=x(EWA_idx);
HF_idx=3:3:6;HF=x(HF_idx);
%I select demand indexing for months and multiply with relevant SWA value.
y1=demand(1:12).*SWA_x(1);
y2=demand(13:24).*SWA_x(2);
z1=demand(1:12)+K*EWAx(1);
z2=demand(13:24)+K*EWAx(2);
%Now, I have to change everything sentence manually and it is very painful task for many years.
% So I want to use for loop or while loop. But, I don't know how to do it and can you kindly guide me please?
% Thank you very much.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!