How to make operation row by row

16 views (last 30 days)
Shahid Said
Shahid Said on 6 May 2021
Commented: Shahid Said on 6 May 2021
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.

Accepted Answer

DGM
DGM on 6 May 2021
Edited: DGM on 6 May 2021
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 Comments
DGM
DGM on 6 May 2021
Edited: DGM on 6 May 2021
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 on 6 May 2021
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.

Sign in to comment.

More Answers (1)

KSSV
KSSV on 6 May 2021
Use:
FtempN =(1 + Alpha_pmp.* (AirTemp(1)-Tstc)) ;
  1 Comment
Shahid Said
Shahid Said on 6 May 2021
Edited: Shahid Said on 6 May 2021
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.

Sign in to comment.

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!