How to save vector from loop?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
i'm solving a cubic equation using roots command, i need only real solution not imaginary. I need to solve this equation for range of 1 to 150, and individual solutions save as a vector. I have a script that save only last solution. Could you please help me? Thanks a lot.
for v=0:150
x=roots([2*ro*A 0 2*ro*A*(2*v+v^2) -P]);
x = x(imag(x)==0);
end
댓글 수: 0
채택된 답변
Star Strider
2019년 10월 20일
The essence of what you have should probably work.
One change:
r{v+1} = x(imag(x)==0);
This saves ‘r’ as a cell array, allowing for differnet numbers of real roots in each iteration. That avoids problems with ‘x’ being both a vector and a cell array.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!