Adding the results of several pcolor graphs...

Hello everyone: I am having difficulties, as I have made a program which calculates some values which it later represents in a pcolor graph (I will paste the code below). The values are calculated one by one in terms of two variables (n_re and n_im) and the color map just indicates the mean difference between my theoretical Contrast (Cteo) and my experimental Contrast (Cexp). The problem is that even though it obtains the correct answers each time (I've tried calculating just one value at a time) if done individually, it only displays in the pcolor graph the last value calculated if a series of values are used (loaded from a table experimental_values_M2612)I need some function or an idea of how I could manage to get each individual result obtained by the program and display it as one overall pcolor graph where I can see a real minimum for ALL my results instead of just one at a time.
function [] = mapa
m=30;
n_re=linspace(1,6,m);
n_im=linspace(0,5,m);
% z=zeros(m,m);
global lambda0;
lambda0=500;
% global z;
% z=[m,m];
load('C:\Users\Weinberg\Desktop\Prueba matlab\Prueba pcolor_V1\Samples\experimental_values_M2612')
tic
for v=1:20
d=Experimental_values(v,1);
Cexp=Experimental_values(v,3);
for i=1:m
for j=1:m
n=n_re(i)+1i*n_im(j);
z(i,j)=cx2(lambda0,d,n,Cexp);
end
end
pcolor(n_re,n_im,z);shading interp; colormap(jet);
toc
end
end
function [x2]=cx2(lambda0,d,n,Cexp)
x2=(Cexp-Cteo(lambda0,d,n)).^2;
end
function [C]=Cteo(lambda0,d,n)
nair=1;
dSiO2=285;
nSi=2
nSiO2=2
%calcular el contraste teorico
mSiO2=Sij(nair,nSiO2)*Pj(nSiO2,dSiO2,lambda0)*Sij(nSiO2,nSi);
mflake= Sij(nair,n)*Pj(n,d,lambda0)...
*Sij(n,nSiO2)*Pj(nSiO2,dSiO2,lambda0)*Sij(nSiO2,nSi);
rSiO2=abs(mSiO2(2,1)/mSiO2(1,1))^2;
rflake=abs(mflake(2,1)/mflake(1,1))^2;
C =(rflake-rSiO2)/(rflake+rSiO2);
end
Any help will be greatly appreciated, and thank to anyone that can help me in advance. Guillermo

댓글 수: 6

Could there be a way for example of getting all the data that appears on each of the plots (even though the previous plots are not showing)and for example add up every single value (for every point on the graph) so that I can get an overall value? This would allow me to see the minimums as these will be the points that have obtained a minimum value in all the graphs that have been drawn as when added it will be the point with the less value. All the other points would have bigger values as in one graph or another of the 20 drawn it shows it's not a minimum value area...I hope you understand
Please I need urgent help for this. Can anyone give me some advice?
Image Analyst
Image Analyst 2012년 4월 19일
It's difficult for us to understand or visualize what you want. Can you upload your data to your favorite web site so people can download it and try your code?
http://www.mathworks.com/matlabcentral/answers/29922-why-your-question-is-not-urgent-or-an-emergency
http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers
First of all, thanks for your answers.
The images will be these:
http://imageshack.us/photo/my-images/207/examplev1.png/
http://imageshack.us/photo/my-images/207/examplev3.png/
http://imageshack.us/photo/my-images/207/examplev8.png/
http://imageshack.us/photo/my-images/207/examplev18.png/
Each of these are with different values for v (v=1,v=3,v=8 and v=18) each meaning a different row in my data table (v=row number in data table)
The blue regions in the images is the minimum at which the difference between my experimental contrasts (Cexp) and my theoretical contrasts (Cteo) is minimum whilst the red areas are the points at which the difference between the theoretical and experimental are most different. As you can see one at a time each graph is displayed correctly, but when done inside a loop, the program only displays the last one that has been calculated.
The best case scenario would be a program that allows me to analyze all the images (for instance adding each individual point's x2 value (which is what is represented with the color)so that in the end the minimum region in the last graph would be an addition of all the minimum areas from all previous graphs.
Thanks again very much to you all
The table of data can be downloaded from
http://www.mediafire.com/?q36jmcxq3nr0cg8
The only thing is that the load folder must be changed in the code from:
load('C:\Users\Weinberg\Desktop\Prueba matlab\Prueba pcolor_V1\Samples\experimental_values_M2612') and change it to whatever folder.

댓글을 달려면 로그인하십시오.

답변 (2개)

Jan
Jan 2012년 4월 19일

1 개 추천

See doc hold. I assume a "hold('on')" behind the pcolor command will fix the axes to draw in.
Another idea would be to create the axes explicitely and setting the 'NextPlot' property:
AxesH = axes('NextPlot', 'add');
for v=1:20
...
pcolor(..., 'Parent', AxesH);

댓글 수: 4

Hold on I've tried using although it seems that it still draws ONLY the last plot. I have just tried it again behind pcolor but still doesn't hold all my plots (as an average pcolor graph), and instead draws only the last calculation for
x2=(Cexp-Cteo(lambda0,d,n)).^2; for the v=20 value.
I will try your Nextplot idea and see if that works. I will write back. Thanks for your quick answer
I've also tried the axes but it isn't working either. The problem is that each time the program does a calculation it just overwrites the color map from the previous one. I can't seem to find a way out of this loop :(
Jan
Jan 2012년 4월 19일
Do you draw the PCOLOR areas to the same location? Then of course the conceal eachother.
I dont use pcolor anymore, I am using Imagesc as Image analyst suggested and although the result is for practical purposes the same (visually) I am obtaining data and not just an image

댓글을 달려면 로그인하십시오.

Image Analyst
Image Analyst 2012년 4월 19일

1 개 추천

I assume you know that pcolor does not color the "tiles" according to what their value is, like image, imagesc, or imshow does. If you didn't know that, then switch to one of those functions.

댓글 수: 5

I didn't know this (I'm still new in Matlab). I'll give it a try if hold on doesn't work like Jan Simon said above.
Ok, I have just tried using image,imagesc and imshow but I've had the exact same result as with pcolor, meaning that only the last calculation is kept and drawn. There seems to be a problem for my program to actually keep the previous calculations and plot them all at the same time on the same graph.
I've had an idea using your comment. Do you know how to save each of the imagesc plots as data? It would be great to have it saved as a matrix for example called h and that I could then summ up all the matrices for as many plots as I have giving me the overall answer for the addition of each individual point in each graph.
I was thinking for example on doing something like
h=imagesc(n_re,n_im,z) (which would save each plot as h, and then add all those matrices. Do you know if that is possible? How would I do so that the variable h saves ALL the plots and not overwrite them? Something like h(i) = imagesc... would work? Thanks in avance
Image Analyst
Image Analyst 2012년 4월 19일
You already have the matrix as a variable. You needed that before you displayed it. If you want to save a picture of the figure window, use export_fig (in the Mathworks File Exchange).
I put up online the data table, and some images...hope it makes it easier for any help. Thank you very much.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

질문:

2012년 4월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by