# How to make operation row by row

1 ビュー (過去 30 日間)
Shahid Said 2021 年 5 月 6 日
コメント済み: Shahid Said 2021 年 5 月 6 日
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.

サインインしてコメントする。

### 回答 (2 件)

KSSV 2021 年 5 月 6 日
Use:
FtempN =(1 + Alpha_pmp.* (AirTemp(1)-Tstc)) ;
##### 1 件のコメント表示非表示 なし
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.

サインインしてコメントする。

DGM 2021 年 5 月 6 日

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 件のコメント表示非表示 2 件の古いコメント
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.

サインインしてコメントする。

R2018a

### Community Treasure Hunt

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

Start Hunting!

Translated by