Matrix divison or calculating slope

5 ビュー (過去 30 日間)
Suzana Kralj
Suzana Kralj 2019 年 5 月 21 日
コメント済み: Suzana Kralj 2019 年 5 月 22 日
Hi everyone!
I am new user of Matlab and I have a problem with basic operations.
So,I have two matrix
tc=[0 0.5 1 2 3 4 5 10 15 20 30 45];
hc=[0.248 0.248 0.248 0.248 0.248 0.248
0.243 0.244 0.246 0.248 0.247 0.248
0.215 0.236 0.241 0.247 0.246 0.248
.....................................];
the thing I need to do is: for each column in matrix hc divide the difference of second and first row with the difference of second and first member of matrix tc, and in next step do the same for third and second member. (this is actually calculating the slope for each experimental data).
For example: slope=(hc(1,1)-(hc(2,1)))/(tc(1,2)-tc(1,1)) or with data (0.248-0.243)/(0.5-0)
My idea was to do that with for loops:
slope=zeros(12,6);%initialization of matrix
for i=1:12 %there are 12 rows in hc full data
for j=1:6
slope(i,j)= ((hc((i),j))-(hc(i+1),j)))/((tc(1,(j+1)))-(tc(1,j)));
end
end
but it's not working. So I would need your help.

採用された回答

Are Mjaavatten
Are Mjaavatten 2019 年 5 月 22 日
編集済み: Are Mjaavatten 2019 年 5 月 22 日
There is a syntax error with your use of parentheses. Also, the slope for the last row is not defined. This should work:
nrows = 3; % Set nrows to 12 for your full data set
slope=zeros(nrows-1,6);
for i=1:nrows-1
for j=1:6
slope(i,j)= (hc(i,j)-hc(i+1,j))/(tc(1,j+1)-tc(1,j));
end
end
  1 件のコメント
Suzana Kralj
Suzana Kralj 2019 年 5 月 22 日
It works!
Thank You really much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by