rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
plot_data_surf.m
1 function plot_data_surf(v, M, Info)
2 % function plot_data_surf(z,M)
3 %
4 %FUnction plots a 3D surfaceplot of given Data.
5 %
6 % v : Vector of measurements
7 % M : Matrix of measurepoints
8 %
9 % v(i) must be result of measurement at measurepoints M(i,:)
10 %
11 %In case of more complex data M (e.g. more than two parameter dimensions),
12 %one can specify the plot in the cells "Info".
13 %
14 %Info{1} : Vector of size two, defining the rows of to be used as
15 % %plotting dimensions
16 %Info{2} : Vector giving the values for the dimensions which are not
17 % plottetd.
18 % dim(Info{2}) = dim(M(1,:))
19 %
20 % Markus Dihlmann 04.02.2010
21 %
22 
23 
24 
25 x=[];
26 y=[];
27 
28 
29 
30 if ~isempty(Info)
31  %must modify M
32  if(length(v(:,1))==1)
33  v=v';
34  end
35  for j=1:length(M(1,:))
36  if(isempty(find(Info{1}==j)))
37  i=1;
38  while(i<=length(M(:,1)))
39  if(M(i,j)~=Info{2}(j))
40  %cancel line
41  if(i==1)
42  M=M(i+1:length(M(:,1)),:);
43  v=v(i+1:length(v));
44  elseif(i>=length(M(:,1)))
45  M=M(1:i-1,:);
46  v=v(1:i-1);
47  else
48  M=[M(1:i-1,:);M(i+1:length(M(:,1)),:)];
49  v=[v(1:i-1);v(i+1:length(v))];
50  end
51  else
52  i=i+1;
53  end
54  end
55  end
56  end
57  Mbuf=M;
58  M=[];
59  M(:,1)=Mbuf(:,Info{1}(1));
60  M(:,2)=Mbuf(:,Info{1}(2));
61  v
62  M
63 
64 end
65 
66 
67 %Sort data of M into axis x and y:
68 x=M(:,1);
69  xmax = max(x);
70  x=[x;xmax+1];
71 y=M(:,2);
72  ymax = max(y);
73  y=[y;ymax+1];
74 
75  %bubblesort x
76  l=length(x)-1;
77  ind=1;
78  while(ind<=l)
79  if(x(ind+1)<x(ind))
80  buf=x(ind+1);
81  x(ind+1)=x(ind);
82  x(ind) = buf;
83  if(ind>1)
84  ind = ind-1;
85  end
86  elseif(x(ind+1)==x(ind))
87  x=cut_vec(x,ind);
88  else
89  ind=ind+1;
90  end;
91  l=length(x)-1;
92  end
93  x=x(1:length(x)-1); %cut last element
94 
95  %bubblesort y
96  l=length(y)-1;
97  ind=1;
98  while(ind<=l)
99  if(y(ind+1)<y(ind))
100  buf=y(ind+1);
101  y(ind+1)=y(ind);
102  y(ind) = buf;
103  if(ind>1)
104  ind = ind-1;
105  end
106  elseif(y(ind+1)==y(ind))
107  y=cut_vec(y,ind);
108  else
109  ind=ind+1;
110  end;
111  l=length(y)-1;
112  end
113  y=y(1:length(y)-1); %cut last element
114 
115  %Sort Values of v in right position on z-Matrix
116  Z=zeros(length(x),length(y));
117  for i=1:length(v)
118  %search x-Value position
119  ind1=search_pos(M(i,1),x);
120  ind2=search_pos(M(i,2),y);
121  Z(ind1,ind2)=v(i);
122  end
123 
124  %Check consistency of given Data and Matrix Z
125  elem = length(Z(:,1))*length(Z(1,:));
126  if(elem~=length(v))
127  disp('Warning: Plot may be not correct due to incomplete given data');
128  end
129  x
130  y
131  Z
132  surf(x,y,Z');
133 
134 end
135 
136 
137 
138 function vec=cut_vec(vec,i)
139  %what type of vector?
140  if(length(vec(1,:))>1)
141  vec_type=0; %Column vector
142  else
143  vec_type=1; %Row vector
144  end;
145 
146  vec_buf = vec(i+1:length(vec));
147  vec=vec(1:i-1);
148 
149  if vec_type
150  vec=[vec;vec_buf];
151  else
152  vec=[vec,vec_buf];
153  end;
154 
155 end
156 
157 
158 function ind=search_pos(value,vec)
159  found=0;
160  ind=1;
161  while ((~found)&&(ind<=length(vec)))
162  if(vec(ind)==value)
163  found=1;
164  else
165  ind = ind+1;
166  end
167  end
168 
169  if(ind>length(vec))
170  ind=-1;
171  error('Error in plotting. Couldnot find index position');
172  end
173 
174 end