Plotting 3 lines with different x values in one single plot?

9 visualizaciones (últimos 30 días)
undefined undefined
undefined undefined el 18 de Abr. de 2020
Comentada: Star Strider el 21 de Abr. de 2020
Hi, I have data of absorbtion spectra of three different materials and I need to plot all of them on the same plot. The problem is that the X for each one isn't the same. For all of them the X axis is the wavelength but in one material this value jumps in 2 and in other it jumps in 25. This means that the wavelength (x value) of each material has a different length and not precisly the same values. However, I need all of them in one plot as in the following image:
My idea is to create a loop that eliminates the wavelengths that not match between the three materials (three vectros) but I don't know how to do it.
Thank you :)

Respuestas (1)

Star Strider
Star Strider el 18 de Abr. de 2020
Use the hold function to plot them individually.
Example —
x1 = sort(rand(1,10));
y1 = rand(size(x1));
x2 = sort(rand(1,27));
y2 = rand(size(x2));
figure
plot(x1, y1)
hold on
plot(x2, y2)
hold off
grid
.
  12 comentarios
undefined undefined
undefined undefined el 21 de Abr. de 2020
I am trying to use the interp function but I get an error alert.
What I need to do is to create the following graph:
The values and data are taken from the mat.files attached (water and Hemoglobin).
The X axis is the wavelength which is the first column in each file. The Y axis is the absorbstion spectra, which is a calculation I was requested to do (appears in the code attached below). In water it's a simple calculation, while in Hemoglobin I was asked to summ columns 2 and three, and I did so.
Finally I need to add a third line which is summing the first two. Example, in x wavelength I need to summ the Y value of Hemoglobin and water. In orther to do that I understan that I must have two vectors with the same length. This is when I tried using interp as following: Y3 = interp(x,1.627) but it didn't work. (1.627 is the ratio between Hemoglobin and water).
In addition, I've attached the instructions for this project, it might help.
lamda.hb = Hemoglobin{:,1};
so2 = Hemoglobin{:,2}*0.1;
hb = Hemoglobin{:,3}*0.9;
epsilon = (so2 + hb).*lamda.hb;
x1 = lamda.hb;
y1 = 0.0054.*0.07.*epsilon;
lamda.water = water{:,1};
mua.water = water{:,2};
x2 = lamda.water;
y2 = 0.0054.*mua.water.*0.75;
y3 = interp(x2,1.627);
figure
loglog(x1, y1, 'r')
hold on
plot(x2, y2, 'b')
hold off
grid
legend('7% Blood ', '75% water')
Star Strider
Star Strider el 21 de Abr. de 2020
I still have no idea what you want to do.
Try this:
y3 = interp1(x1, y1, x2, 'linear','extrap');
figure
loglog(x1, y1)
hold on
plot(x2, y2)
plot(x2, y2+y3)
hold off
grid
legend('\epsilon', 'H_2O', 'y_2+y_3')
.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by