My matlab plot is not showing up anymore

Hi. I am plotting a graph, more specifically, the intensity of light against the points on a screen (a physics experiment). At first, my plot showed up with no problem, but after a while, my plot suddenly stopped showing up. There are no error numbers. Where my plot should be is now simply a grey, empty space. I searched for solutions and saw that people have had this problem before, but none of the solutions suggested have worked for me. Would anyone know why my plot is not showing up?
Here is some of my code:
clear all
clf
lambda = 700*10^-7;
a=-7;
b=0.1;
c=7;
distances_one = [];
first_intensity_vector = [];
for x = a:b:c
l = 10;
x3 = 10^-3;
djx = sqrt((l^2)+(x-x3)^2);
distances_one = [distances_one,djx];
intensity_one = abs(exp((complex(0,1)*2*pi*djx)/lambda));
first_intensity_vector = [first_intensity_vector, intensity_one];
end
(same thing for two, three, four and five)
fiv = first_intensity_vector;
siv = second_intensity_vector;
tiv = third_intensity_vector;
fuiv= fourth_intensity_vector;
fiiv= fifth_intensity_vector;
figure
tot_intensity_vector = fiv + siv + tiv + fuiv + fiiv
plot(tot_intensity_vector,screen_x_values, "r-")
Here is an image of how it looks:
Simply a grey, empty space where my plot should be.
I would appreciate help greatly.
Thank you at beforehand.

2 commentaires

same thing here. I also tried with the most simple of plots, like:
x = 0:pi/100:2*pi;
y = sin(x);
plot(x,y)
but nothing is showing
William
William le 11 Sep 2025
Modifié(e) : William le 11 Sep 2025
I had the same problem and it was solved when I restarted r2025 and waited patiently for it to intialize before running any scripts. Seems to have been cause by running scripts before R2025 was ready. Thank you!!

Connectez-vous pour commenter.

 Réponse acceptée

KALYAN ACHARJYA
KALYAN ACHARJYA le 14 Avr 2025
Modifié(e) : KALYAN ACHARJYA le 14 Avr 2025
clear all
clf
lambda = 700*10^-7;
a = -7;
b = 0.1;
c = 7;
x_vals = a:b:c; % Store x values, Is that x values
distances_one = [];
first_intensity_vector = [];
for x = x_vals
l = 10;
x3 = 10^-3;
djx = sqrt((l^2)+(x-x3)^2);
distances_one = [distances_one,djx];
intensity_one = abs(exp((complex(0,1)*2*pi*djx)/lambda));
first_intensity_vector = [first_intensity_vector, intensity_one];
end
fiv = first_intensity_vector; % Change the data with real values
siv = first_intensity_vector; % Change the data with real values
tiv = first_intensity_vector; % Change the data with real values
fuiv = first_intensity_vector; % Change the data with real values
% Total intensity
tot_intensity_vector = fiv + siv + tiv + fuiv + fuiv;
figure;
plot(x_vals, tot_intensity_vector, 'r-');
xlabel('Screen Position (x)');
ylabel('Total Intensity');
grid on;
Is that, are you looking for?

7 commentaires

Ellinor
Ellinor le 14 Avr 2025
Modifié(e) : Ellinor le 14 Avr 2025
Yes, it is! May I please ask if you know why the code is working for you? I have the same code (except more code since I have code for intensity vector two, three and so on)?
Thank you!
Edit: now I see you changed second, third and so on to first.
Ellinor
Ellinor le 14 Avr 2025
and yes, I had my x-values on the y-axis, I understand it was confusing.
KALYAN ACHARJYA
KALYAN ACHARJYA le 14 Avr 2025
Modifié(e) : KALYAN ACHARJYA le 14 Avr 2025
Solved? @Ellinor
Ellinor
Ellinor le 14 Avr 2025
Well, I still don't really understand why my plot only shows a grey empty space. Maybe there is no answer to that. But yes, your code worked. I am just worried it will happen again soon. But thank you!
The variables used in the code must be defined before they are referenced. The gray window appears due to the figure; function, but the rest of the code is not executable because the required variables () have not been defined.
siv = second_intensity_vector;
tiv = third_intensity_vector;
fuiv= fourth_intensity_vector;
fiiv= fifth_intensity_vector;
Ellinor
Ellinor le 15 Avr 2025

Hello. Thank you so much for your answer. However, I defined those variables in my code, I simply didn't post all my code, I only posted the code for the fifth intensity vector.

I can reproduce the grey figure window with:
figure;
However, if I specify a few parameters using:
figure('Color','w','Position',[200 200 800 500]);
A different window pops up plotting the figure correctly. Maybe worth a try!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by