need help to find all results in one table , or any possible form
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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'})
%or table(T(:,1),T(:,2),T(:,3),'VariableNames',{'R1','R2','y'})
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!