Value of a variable not changing in the workspace ??

The value of j goes upto 1025 but i stays at 255 itself ,what's the error in this nested loop??
X = load('x.mat');
Y = load('y.mat');
for i=245:61503
i = i+10;
for j=1:1024
j=j+1;
figure(); hold on
plot(Y.y(1:i,j))
set(0,'DefaultFigureWindowStyle','docked')
end
end
hold off

5 commentaires

Rik
Rik le 18 Fév 2019
Why would you change your loop indices like that? If you want them to have those values, why not change them in your call to for? Also, what give you the impression that j stays at 255? Do you get an error? Why are you opening 1024 figures? That seems like it is not visually usefull and will probably cause performance issues.
As a last remark: I would discourage the use of i and j as loop variables. They may cause confusion (and bugs) as they are also the imaginary unit. If you want to use the imaginary unit, use 1i or 1j to avoid any ambiguity.
I would like to get a 3D plot of it ,so I thought to use surf from the obtained 2D plot.
I got this error : Index in position 2 exceeds array bounds (must not exceed 1024).
I tried to use meshgrid ,followed by surf to get a 3D figure but it failed ??
Also tried with the reshape to obtain a 3D and it seems not working great as it has varying no.of.elements .
X = load('x.mat'); %1x1024 double
Y = load('y.mat'); % 61503x1024
rows = 61503;
cols = 1024;
samples = 61503; % possible samples
Data = reshape(Y,rows,cols,samples);
Data = flip(X,1);
figure
surf(abs(sqrt(log10(sum(Data.^2,3))))); shading interp; view(2); set(gcf,'Renderer','zbuffer'); axis equal
print('-djpeg','-r200',['logRMS_', filename(1:end-4), '.jpg']);
Rik
Rik le 18 Fév 2019
Why don't you try explaining what you want to do? That way we can try to solve your actual issue, instead of the errors from your solution.
Alright I have x =1x1024 and y = 61503x1024 matrices
X =x,Y=y
I'm trying to plot a 2D plot and 3D plot for it at every 10th step:
Like for y 1:247 and then y 247:494 till 61503 , x goes as 1 and linearly to 1024
so the normal plot goes as for 2D : plot(Y.y(1:247,1) for the first plot and goes on
I would like to convert this data to 3D values and then plot surf for it.
May be not for all the values just for 1,mid value and end value.

Connectez-vous pour commenter.

 Réponse acceptée

ibabinaca
ibabinaca le 18 Fév 2019
Modifié(e) : ibabinaca le 18 Fév 2019
Why are you putting j = j+1? There is no need to put it with matlab.
X = load('x.mat');
Y = load('y.mat');
for i=245:10:61503
for j=1:1024
figure(); hold on
plot(Y.y(1:i,j))
set(0,'DefaultFigureWindowStyle','docked')
end
end
hold off
By the way, 245+10*n is never going to be 61503

3 commentaires

Rik
Rik le 18 Fév 2019
This code solves the error, but not the issue. This will still open 1024 figures for every i it iterates over. Your computer (or just Matlab) will probably crash.
Alright you're right , for i=247:10:61503 this goes to 61503.
Could you lemme know how can I convert it to 3D values and the plot a surf out of it?
Alright matlab crashes for sure :) due to rendering issues.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by