How to run a for loop n times with a different size matrix inside the loop
Show older comments
I am attempting to run the four values of x_o and y_o through the loop to do conformal mapping. The matrix size of the circle in the loop is different, but I need to run it four times, with four different output graphs. Is this possible in MATLAB? Thanks
Here is what I have so far:
x_o = [0.1, 0.15, 0.2, 0.25]; y_o = [0.1, 0.15, 0.2, 0.25]; n = length(x_o);
for i = 1:n
R = 1;
theta = linspace(0,2*pi,100);
x = R*cos(theta) - x_o;
y = R*sin(theta) + y_o;
b = sqrt(R^2 - y_o.^2) + x_o;
A = x + [(x.*b.^2)./(x.^2 + y.^2)];
B = y - [(y.*b.^2)./(x.^2 + y.^2)];
figure
plot(x,y,'--',A,B)
grid on
end
3 Comments
"...I need to run it four times, with four different output graphs. Is this possible in MATLAB?"
Of course, that is what loops are for: just change the plotted data inside the loop, and you will get four different plots (the data you currently plot is exactly the same on each loop iteration).
BryanE
on 5 Sep 2018
Stephen23
on 5 Sep 2018
"My problem is that the matrix don't agree"
Don't agree with what?
Please given an actual example of the inputs and outputs that you expect to get.
Accepted Answer
More Answers (0)
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!