How to make operation row by row
16 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
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
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
More Answers (1)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!