Hello experts,
this is my code contain:
Alpha_pmp is 400,000 row data
AirTemp is 105200 row data
Tstc is 400,000 row data
below is the formula to calculate FtempN
i can get all the result by using below code:
FtempN =((1 + (Alpha_pmp(1)).* (AirTemp(:,1)-(Tstc(1)))))
if i use above code matlab will return on single row result.
my question is how to to calculate result A by read row by row
for Alpha_pmp and Tstc?
example :
FtempN =((1 + (Alpha_pmp(2)).* (AirTemp(:,1)-(Tstc(2)))))
FtempN =((1 + (Alpha_pmp(3)).* (AirTemp(:,1)-(Tstc(3)))))
FtempN =((1 + (Alpha_pmp(4)).* (AirTemp(:,1)-(Tstc(4)))))
FtempN =((1 + (Alpha_pmp(5)).* (AirTemp(:,1)-(Tstc(5)))))
FtempN =((1 + (Alpha_pmp(6)).* (AirTemp(:,1)-(Tstc(6)))))
until last row.
Thank you.
note : i am newbie.I tried to make some research on matlab web but not luck.

 채택된 답변

DGM
DGM 2021년 5월 6일
편집: DGM 2021년 5월 6일

1 개 추천

Orient the vectors accordingly and use implicit vector expansion. For example:
% these are all column vectors
% A and C have the same length, but B is shorter
A = (1:20)';
B = (1:10)';
C = A;
% D is now 20x10
% note that B is transposed into a row vector, hence the width of D
D = 1 + A .* (B.' - C)
This implicit array expansion works in R2016b and newer. In older versions, you can use bsxfun():
D = 1 + bsxfun(@times,A,bsxfun(@minus,B.',C))

댓글 수: 3

Shahid Said
Shahid Said 2021년 5월 6일
% these are all column vectors
% A and C have the same length, but B is shorter
A = Alpha_pmp';
B = AirTemp';
C = Tstc';
% D is now 20x10
% note that B is transposed into a row vector, hence the width of D
D = 1 + A .* (B.' - C)
Thanks sir.
but i dun think this is the correct code to get my expected result.
DGM
DGM 2021년 5월 6일
편집: DGM 2021년 5월 6일
In the example, A, B, C are column vectors because they're analogous to the column vectors you're using.
AirTemp';
isn't a column vector. It's a Mx150k array. I don't know what M is, because you never said how wide AirTemp was.
AirTemp(:,1)
is a column vector from an array of unknown width. That's all I have to go on.
This should give a 400kx150k array, which will be huge -- problematically huge, but that seems to be what you're trying to calculate.
FtempN = 1 + Alpha_pmp.* (AirTemp(:,1).' - Tstc);
This would give a 150kx400k array instead
FtempN = 1 + Alpha_pmp.' .* (AirTemp(:,1) - Tstc.');
Fwiw, consider that there's 8 bytes per element of a double precision array:
400E3*150E3*8
ans =
4.8000e+11
Shahid Said
Shahid Said 2021년 5월 6일
this is what i intended to do
I think i dun get the result as expected.
my parameter is
Alpha_pmp have 400k rows
Air Temp have 150k rows
Tstc have 400k rows
so from above I run the code as manual as below :
this is how the code should run in manual
FtempN =1 + ((Alpha_pmp(1)).* (AirTemp(:,1)-(Tstc(1))))
then store in table set1
FtempN =1 + ((Alpha_pmp(2)).* (AirTemp(:,1)-(Tstc(2))))
then store in table set2
FtempN =1 + ((Alpha_pmp(3)).* (AirTemp(:,1)-(Tstc(3))))
then store in table set3
until
FtempN =1 + ((Alpha_pmp(400000)).* (AirTemp(:,1)-(Tstc(400000))))
then store in table set400000
or
create new table nama FtempN_result
FtempN =1 + ((Alpha_pmp(1)).* (AirTemp(:,1)-(Tstc(1))))
then store in FtempN_result column 1
FtempN =1 + ((Alpha_pmp(2)).* (AirTemp(:,1)-(Tstc(2))))
tthen store in FtempN_result column 2
FtempN =1 + ((Alpha_pmp(3)).* (AirTemp(:,1)-(Tstc(3))))
tthen store in FtempN_result column 3
until
FtempN =1 + ((Alpha_pmp(400000)).* (AirTemp(:,1)-(Tstc(400000))))
then store in FtempN_result column 400000
then transpose the table.
so how to run the above code using FOR or any other method ?
my expected result is I will have 400,000 table which each one have 150k rows.
or have 400k of column and 150k of row and transpose the table.
thanks sir for your reply.i am really appreciate.

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

추가 답변 (1개)

KSSV
KSSV 2021년 5월 6일

1 개 추천

Use:
FtempN =(1 + Alpha_pmp.* (AirTemp(1)-Tstc)) ;

댓글 수: 1

Shahid Said
Shahid Said 2021년 5월 6일
편집: Shahid Said 2021년 5월 6일
I think i dun get the result as expected.
my parameter is
Alpha_pmp have 400k rows
Air Temp have 150k rows
Tstc have 400k rows
so from above I run the code as manual as below :
this is how the code should run in manual
FtempN =1 + ((Alpha_pmp(1)).* (AirTemp(:,1)-(Tstc(1))))
then store in table set1
FtempN =1 + ((Alpha_pmp(2)).* (AirTemp(:,1)-(Tstc(2))))
then store in table set2
FtempN =1 + ((Alpha_pmp(3)).* (AirTemp(:,1)-(Tstc(3))))
then store in table set3
until
FtempN =1 + ((Alpha_pmp(400000)).* (AirTemp(:,1)-(Tstc(400000))))
then store in table set400000
or
create new table nama FtempN_result
FtempN =1 + ((Alpha_pmp(1)).* (AirTemp(:,1)-(Tstc(1))))
then store in FtempN_result column 1
FtempN =1 + ((Alpha_pmp(2)).* (AirTemp(:,1)-(Tstc(2))))
tthen store in FtempN_result column 2
FtempN =1 + ((Alpha_pmp(3)).* (AirTemp(:,1)-(Tstc(3))))
tthen store in FtempN_result column 3
until
FtempN =1 + ((Alpha_pmp(400000)).* (AirTemp(:,1)-(Tstc(400000))))
then store in FtempN_result column 400000
then transpose the table.
so how to run the above code using FOR or any other method ?
my expected result is I will have 400,000 table which each one have 150k rows.
or have 400k of column and 150k of row and transpose the table.
Thank you sir.

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2021년 5월 6일

댓글:

2021년 5월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by