フィルターのクリア

need help to find all results in one table , or any possible form

1 回表示 (過去 30 日間)
hasan s
hasan s 2021 年 9 月 28 日
コメント済み: hasan s 2021 年 9 月 29 日
Hello, every one
I need to calculate the equation
y=sum((x - 4).^2) / 2; for every R1 less than R2
( where x contain a, b which contains many numbers)
and , Is it possible in matlab to get the results in one table that contains all results (or something similar to the table, or any form) so that it is easy to see all the results from all loops as
R2 R1 y
(or p3 p1 y, as my code),??? therefore % I try to repeat p2 to get the suitable table , for the need for every R1 less than R2, I thought I must repeat R2 to the length(R1)
the error of my result in my code is
Unrecognized function or variable 'p3'.
Error in average (line 22)
T=table(p3,p1,y)
if any prof can help me to correct my code, thanks alot

採用された回答

Kevin Holly
Kevin Holly 2021 年 9 月 29 日
Is this what you were trying to do?
R1=1:1:10;
R2=1:1:10;
a=[22 17 20 7 33 19 8 30 4 9 36 14 12 44 40 ]';
b=[25 18 44 26 35 33 9 44 8 22 40 15 22 50 50]';
T =[];
for j=1:length(R2)
y=0;
for i=1:length(R1)
if R1(i)<R2(j)
x=((1/2)*((b-a)*R1(i)-(b-a)*R2(j)+(b+a)));
y=y+sum((x - 5).^2) / 2;
T = [T; [R1(i) R2(j) y]];
end
end
end
array2table(T,'VariableNames',{'R1','R2','y'})
ans = 45×3 table
R1 R2 y __ __ ______ 1 2 3065 1 3 2337.2 2 3 5402.2 1 4 2055 2 4 4392.2 3 4 7457.2 1 5 2218.2 2 5 4273.2 3 5 6610.5 4 5 9675.5 1 6 2827 2 6 5045.2 3 6 7100.2 4 6 9437.5 5 6 12502 1 7 3881.2
%or table(T(:,1),T(:,2),T(:,3),'VariableNames',{'R1','R2','y'})
  1 件のコメント
hasan s
hasan s 2021 年 9 月 29 日
Excellent work,,,yes, this is what I tried and could not
Thank you so much prof Kevin

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by