Plotting multiple graphs but only a graph is shown

I tried to create circles with different radii in one figure. I have put the data of the radii in an array and try to plot the curves. However, only the circle with largest radius shown. I have checked the array a(i,1) is not zero at all. In case the file 'numberden' is needed, I have attached the file here.
clear
clc
clf
R_MAX=sqrt(3)*2*50;
mr=0.025;
dr=(R_MAX-mr)/1000;
filename = 'numberden0.txt';
A=importdata(filename);
ei=A(:,1);
ej=A(:,2);
i=0;
a=zeros(1000,1);
for i=1:1:1000
if (ei(i)~=0)
a(i,1)=ej(i);
elseif (ei(i)==0)
a(i,1)=0;
end
end
a;
theta=linspace(0,2*pi,1000);
for j=1:1:1000
x=a(i,1)*sin(theta);
y=a(i,1)*cos(theta);
hold on
scatter(x,y,'.')
hold off
end

 Risposta accettata

KSSV
KSSV il 15 Mag 2020
You must remove hold off in the for loop.

7 Commenti

Simon219
Simon219 il 15 Mag 2020
Modificato: Simon219 il 15 Mag 2020
where should I put the hold off ? after the loop? I have also tried to put it after the for loop but it does not work. Still only one circle is shown.
theta=linspace(0,2*pi,1000);
figure
hold on
for j=1:1:1000
x=a(i,1)*sin(theta);
y=a(i,1)*cos(theta);
scatter(x,y,'.')
end
hold off
But for the above, you need not to use a loop.
theta = linspace(0,2*pi,length(a)) ;
x = a.*sin(theta) ;
y = a.*cos(theta) ;
% scatter plot
figure
scatter(x,y)
% line plot
figure
plot(x,y)
% marker
figure
plot(x,y,'.')
I have tried the first code you provided which does not work still. Two figure windows appeared, the first one is empty and the second one is the scatter plot. However, I could see only one curve in the figure of sctter curve which I attached here. For the second code, error message appeared "Error using scatter (line 78)" (there are 49 lines at most in the code) and "X and Y must be vector of the same length".
Attach your file....this is a very simple task.
I attached the file here.
filename = 'numberden0.txt';
A=importdata(filename);
ei=A(:,1);
ej=A(:,2);
a = zeros(size(ei)) ;
a(ei~=0) = ej(ei~=0) ;
theta=linspace(0,2*pi,length(a))';
x = a.*sin(theta) ;
y = a.*cos(theta) ;
plot(x,y,'.r')
Thanks, here is what I got for the garph (graph.fig). However I found polarplot maybe a better tool for me since what I want is several circles with different radius. So I have the code:
r=ones(1,360);
hold on
for i=1:1:length(a)
theta=linspace(0,2*pi,length(a));
k=a(i)*r
polarscatter(theta, k)
end
hold off
Error appeared that adding polar plot axes is not supported. What's wrong with that

Accedi per commentare.

Più risposte (0)

Richiesto:

il 15 Mag 2020

Commentato:

il 15 Mag 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by