create a specific vector from excel file

조회 수: 11 (최근 30일)
MUKESH KUMAR
MUKESH KUMAR 2017년 8월 4일
댓글: Jan 2017년 8월 9일
I want create a zero vector (1*24) and according to the appliances like for 'lights' (in Excel file ) create A1 zero vector (1*24) ,start and end time shows that A1 zero vector replace power value of 0.5 between 18-24 in row vector but the condition is that this 0.5 values put only 6 places randomly between 18-24. And similarly for all appliances. Like PHEV A17 vector it should contain 2.5 power value at 20-21-22-23-24-1-2-3-4-5-6 only for 4 (hours ) place randomly at any place between 20-6 .
  댓글 수: 3
MUKESH KUMAR
MUKESH KUMAR 2017년 8월 4일
read the attached excel file there and i assume A1 vector for lights and A2 for refrigerator ,A3 for electric stove and so on....... output should be like A1=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.5 0 0.5 0.5 0.5 0.5]; A2=[0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125];%0.125 placed between 1-24 in 1*24 vector only for 24 hours(G2 value in excel). A3=[0 0 0 0 0 0 1.5 1.5 0 0 1.5 0 0 0 0 0 0 0 0 0 0 0 0 0];% 1.5 placed between 6-14th in 1*24 vector only for 3hours(G3 value in excel).

댓글을 달려면 로그인하십시오.

채택된 답변

KL
KL 2017년 8월 8일
If I understood correctly, the following is what you're looking for. It's basically the same as Jan's but I just did it for the rest of the data from your excel file
data = xlsread('apdata.xls');
data_len = length(data);
A = zeros(18,data_len);
fi = @(a,b) ([a:data_len 1:b]);
for i = 1:data_len
pVec = data(i,3)*ones(data(i,5),1);
if(data(i,1)<data(i,2))
ind = data(i,1):data(i,2);
else
ind = fi(data(i,1),data(i,2));
end
x = randperm(numel(ind));
x = x(1:data(i,5));
A(i,ind(x)) = pVec;
end
  댓글 수: 2
MUKESH KUMAR
MUKESH KUMAR 2017년 8월 8일
thanks 100% right that I need ,I got from matrix A .
MUKESH KUMAR
MUKESH KUMAR 2017년 8월 9일
but if I create a matrix for a single value of 'i' without loop then its create only vector A size 18*18 but i require A vector of 18*24 or 1*24 for single value of 'i'. explain the following code:
fi = @(a,b) ([a:data_len 1:b]);

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jan
Jan 2017년 8월 4일
All I understand from the question is: "0.5 values put only 6 places randomly between 18-24":
A1 = zeros(1, 24);
index = 18:24;
index = index(randperm(1:7, 6));
A1(index) = 0.5;
Easier:
A1 = zeros(1, 24);
A1(18:24) = 0.5;
A1(randi([18, 24], 1)) = 0;
I have no idea, what the rest of the question means.
  댓글 수: 4
MUKESH KUMAR
MUKESH KUMAR 2017년 8월 8일
still did not understand my question?
Jan
Jan 2017년 8월 9일
No, I do not understand it. "simillary for all appliances like for 'TV' (in Excel file )" What is a "appliance", what is "TV", what does "in Excel file" mean? What is an "A5 zero vector (1*24)"? "start and end time shows that A1 zero vector replace power value of 0.25 between 16-24"?
Sorry, I do not understand any sentence of the explanation. If KL#s answer solves your problem, it is not worth to explain it again.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by