need help to find all results in one table , or any possible form
조회 수: 1 (최근 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에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!