MATLAB: Getting a single value out of vpasolve with growing matrix

debuggrowing matrixnon-singleton subscrips

The equation "E" has two roots and I am only interested in the positive root. the function for To5 keeps growing to a predefined point, my trouble is that I'm getting this error occurring at the second line of code: "Assignment has more non-singleton rhs dimensions than non-singleton subscripts"
E = (1+R)*(Ym*Rg)*To5(i,2) + fo/(1+R)*Qr + (1+R+fo/(1+R) == 0.12*(1+R))*Yc*Rg*To6;
R(i,2) = vpasolve(E,R, [0 Inf]); %Step 6
I believe the problem is due to my not using vpasolve correctly in getting just the positive value out of the function and then assigning it to the growing matrix R, know how I can fix this?

Best Answer

You didn’t post the rest of your code, and it doesn’t work with the code you previously posted, so I can only post an example:
syms x
R = vpasolve(x^2 - x - 4 == 0)
ReR = R(real(R) > 0)
R =
-1.561552812808830274910704927987
2.561552812808830274910704927987
ReR =
2.561552812808830274910704927987
It’s relatively easy to select the solution that is greater than zero, or any number of other conditions.