How to solve Ax=b when some values of x are known and b is vector of zeros - matlab

I have a matrix Q=A (64x64), a vector f=b is vector of zeros and I know some values of x=q. I know that I should transfer the corresponding column and row (of known x=q) on the right side of the equation (to b), but I don't know, how to make it in Matlab. I should to do that for 1st, 5th, 9th, 13th, 17th, 21st, 25th, 29th, 33th, 37th, 41st, 45th, 49th, 53th, 57th and 61st, column and row. Can you help me, pls?
This is the program:
clear all;
K=zeros(64,64);
f=zeros(64,1);
ne=32;
E= 8000; %Young
P= 0.51; %Poisson
Lambda=(E*P)/((1+P)*(1-2*P));
Eta=E/(2*(1+P));
%ILOK
ILOK=[
1 3 5 7 2 4 6 8;
5 7 9 11 6 8 10 12;
9 11 13 15 10 12 14 16;
13 15 17 19 14 16 18 20;
17 19 21 23 18 20 22 24;
21 23 25 27 22 24 26 28;
25 27 29 31 26 28 30 32;
29 31 33 35 30 32 34 36;
33 35 37 39 34 36 38 40;
37 39 41 43 38 40 42 44;
41 43 45 47 42 44 46 48;
45 47 49 51 46 48 50 52;
49 51 53 55 50 52 54 56;
53 55 57 59 54 56 58 60;
57 59 61 63 58 60 62 64;
61 63 1 3 62 64 2 4;
3 0 7 0 4 0 8 0;
7 0 11 0 8 0 12 0;
11 0 15 0 12 0 16 0;
15 0 19 0 16 0 20 0;
19 0 23 0 20 0 24 0;
23 0 27 0 24 0 28 0;
27 0 31 0 28 0 32 0;
31 0 35 0 32 0 36 0;
35 0 39 0 36 0 40 0;
39 0 43 0 40 0 44 0;
43 0 47 0 44 0 48 0;
47 0 51 0 48 0 52 0;
51 0 55 0 52 0 56 0;
55 0 59 0 56 0 60 0;
59 0 63 0 60 0 64 0;
63 0 3 0 64 0 4 0;
];
%x
xm=[
9.000 14.500 8.315 13.396;
8.315 13.396 6.364 10.253;
6.364 10.253 3.444 5.549;
3.444 5.549 0.000 0.000;
0.000 0.000 -3.444 -5.549;
-3.444 -5.549 -6.364 -10.253;
-6.364 -10.253 -8.315 -13.396;
-8.315 -13.396 -9.000 -14.500;
-9.000 -14.500 -8.315 -13.396;
-8.315 -13.396 -6.364 -10.253;
-6.364 -10.253 -3.444 -5.549;
-3.444 -5.549 0.000 0.000;
0.000 0.000 3.444 5.549;
3.444 5.549 6.364 10.253;
6.364 10.253 8.315 13.396;
8.315 13.396 9.000 14.500;
14.500 20.000 13.396 18.748;
13.396 18.748 10.253 14.142;
10.253 14.142 5.549 7.654;
5.549 7.654 0.000 0.000;
0.000 0.000 -5.549 -7.654;
-5.549 -7.654 -10.253 -14.142;
-10.253 -14.142 -13.396 -18.748;
-13.396 -18.748 -14.500 -20.000;
-14.500 -20.000 -13.396 -18.748;
-13.396 -18.748 -10.253 -14.142;
-10.253 -14.142 -5.549 -7.654;
-5.549 -7.654 0.000 0.000;
0.000 0.000 5.549 7.654;
5.549 7.654 10.253 14.142;
10.253 14.142 13.396 18.748;
13.396 18.748 14.500 20.000;
];
%y
ym=[
0.000 0.000 3.444 5.549
3.444 5.549 6.364 10.253
6.364 10.253 8.315 13.396
8.315 13.396 9.000 14.500
9.000 14.500 8.315 13.396
8.315 13.396 6.364 10.253
6.364 10.253 3.444 5.549
3.444 5.549 0.000 0.000
0.000 0.000 -3.444 -5.549
-3.444 -5.549 -6.364 -10.253
-6.364 -10.253 -8.315 -13.396
-8.315 -13.396 -9.000 -14.500
-9.000 -14.500 -8.315 -13.396
-8.315 -13.396 -6.364 -10.253
-6.364 -10.253 -3.444 -5.549
-3.444 -5.549 0.000 0.000
0.000 0.000 5.549 7.654
5.549 7.654 10.253 14.142
10.253 14.142 13.396 18.748
13.396 18.748 14.500 20.000
14.500 20.000 13.396 18.748
13.396 18.748 10.253 14.142
10.253 14.142 5.549 7.654
5.549 7.654 0.000 0.000
0.000 0.000 -5.549 -7.654
-5.549 -7.654 -10.253 -14.142
-10.253 -14.142 -13.396 -18.748
-13.396 -18.748 -14.500 -20.000
-14.500 -20.000 -13.396 -18.748
-13.396 -18.748 -10.253 -14.142
-10.253 -14.142 -5.549 -7.654
-5.549 -7.654 0.000 0.000
];
%Ke a fe of element
for k=1:ne
x=xm(k,:);%k-ty radek x-ove matice
y=ym(k,:);%k-ty radek y-ove matice
Au=zeros(4,4);
Av=zeros(4,4);
Auv=zeros(4,4);
Avu=zeros(4,4);
%Numerical integration
for i=1:9
a=0.774596669241483;
gaus=[1 0 0 68/81;
2 0 a 40/81;
3 a 0 40/81;
4 0 -a 40/81;
5 -a 0 40/81;
6 a a 25/81;
7 a -a 25/81;
8 -a -a 25/81;
9 -a a 25/81];
r=gaus(i,2);
s=gaus(i,3);
N=[(1/4)*(1-r)*(1-s);
(1/4)*(1+r)*(1-s);
(1/4)*(1+r)*(1+s);
(1/4)*(1-r)*(1+s)];
Nr=[(1/4)*(s-1);
(1/4)*(1-s);
(1/4)*(s+1);
(1/4)*(-s-1)];
Ns=[(1/4)*(r-1);
(1/4)*(-1-r);
(1/4)*(r+1);
(1/4)*(1-r)];
%Jacob matrix
j1=Nr'*x';
j2=Nr'*y';
j3=Ns'*x';
j4=Ns'*y';
J=[j1 j2;
j3 j4];
detJ=abs(det(J));
invJ=inv(J);
%Nx a Ny
Nx=invJ(1,1)*Nr+invJ(1,2)*Ns;
Ny=invJ(2,1)*Nr+invJ(2,2)*Ns;
ds=gaus(i,4)*detJ;
Au=Au+(Nx*(Lambda*Nx'+2*Eta*Nx')+Eta*Ny*Ny')*ds;
Av=Av+(Ny*(Lambda*Ny'+2*Eta*Ny')+Eta*Nx*Nx')*ds;
Auv=Auv+(Nx*Lambda*Ny'+Eta*Ny*Nx')*ds;
Avu=Avu+(Ny*Lambda*Nx'+Eta*Nx*Ny')*ds;
Ke=[Au Auv;
Avu Av];
fe=zeros(8,1);
end
%K a f
N=8;
je=1:N;
mg(je)=ILOK(k,je);
igl=mg;
inen=find(igl);
K(igl(inen),igl(inen))=K(igl(inen),igl(inen))+Ke(igl>0,igl>0);
f(igl(inen))=f(igl(inen))+fe(igl>0);
Ke=zeros(8,8);
fe=zeros(8,1);
end
K;
And then I need to solve q=K/f
I would like transfer the columns a rows from this matrix to f (in this case).
Thank you for your help :)

This is known as solving for the null space of a matrix.
Z = null(A)
Z = null(A,'r')
Z = null(A) is an orthonormal basis for the null space of A obtained
from the singular value decomposition. That is, A*Z has negligible
elements, size(Z,2) is the nullity of A, and Z'*Z = I.
Z = null(A,'r') is a "rational" basis for the null space obtained from
the reduced row echelon form. A*Z is zero, size(Z,2) is an estimate
for the nullity of A, and, if A is a small matrix with integer
elements, the elements of the reduced row echelon form (as computed
using rref) are ratios of small integers.
The orthonormal basis is preferable numerically, while the rational
basis may be preferable pedagogically.
Please refer to the fully worked out examples in the References section below, as they include MATLAB-specific examples, and worked out "by hand" solutions.
Good luck!
References
http://www.mathworks.com/help/matlab/ref/null.html
http://www.math.sunysb.edu/~badger/mat211f12/solver.pdf

Related

Why i didn't get the complete decision tree(I mean all attributes)?

I used decision tree classifier in MATLAB. I used 7 attributes.But when i draw the decision tree it doesn't includes all attributes,it only includes 2 or 1 attributes.What is the problem of my code?
vars = {'Asymmetry' 'Border irregularity' 'colors' 'contrast' 'Co-relation'
'Homogeneity' 'Energy'};
x = [0.148 0.298 3 0.027 0.959 0.992 0.692
0.248 0.462 3 0.015 0.997 0.996 0.837
0.683 0.827 3 0.030 0.974 0.989 0.634
0.170 0.509 3 0.065 0.964 0.977 0.399
0.663 0.764 3 0.061 0.945 0.983 0.645
0.641 0.671 3 0.050 0.953 0.987 0.703
0.653 0.796 2 0.062 0.961 0.981 0.528
0.458 0.704 2 0.019 0.934 0.993 0.852
0.555 0.729 2 0.087 0.976 0.980 0.380
0.454 0.657 2 0.059 0.953 0.982 0.467
0.379 0.497 2 0.058 0.976 0.979 0.445
0.443 0.486 2 0.034 0.896 0.998 0.810
0.194 0.342 2 0.012 0.956 0.997 0.895
0.248 0.462 3 0.015 0.977 0.996 0.837
0.155 0.340 2 0.010 0.930 0.966 0.911
0.458 0.704 2 0.019 0.934 0.993 0.852];
y = {'Cancer';'Cancer';'Cancer';'Cancer';'Cancer';'Cancer';'Cancer';'Cancer';'Cancer';'Cancer';'Cancer';'Cancer';'non-Cancer';'non-Cancer';'non-Cancer';'non-Cancer'};
t = fitctree(x,y,'PredictorNames',vars, ...
'CategoricalPredictors',{},'Prune','off');
view(t);
X1=[0.148 0.186 2 0.139 0.984 0.992 0.558]
label = predict(t,X1);
view(t,'mode','graph');
The output image of the code:
There's nothing wrong with your code - the decision tree is not designed to use all of your variables, it's just designed to use the variables that give the best fit based on the given decision criteria. Using all of the variables would result in overfitting, especially considering that some of your variables are correlated with each other.

classifier.setOptions( weka.core.Utils.splitOptions()) is taking only default values even if other values provided in matlab

import weka.core.Instances.*
filename = 'C:\Users\Girish\Documents\MATLAB\DRESDEN_NSC.csv';
loader = weka.core.converters.CSVLoader();
loader.setFile(java.io.File(filename));
data = loader.getDataSet();
data.setClassIndex(data.numAttributes()-1);
%% classification
classifier = weka.classifiers.trees.J48();
classifier.setOptions( weka.core.Utils.splitOptions('-C 0.25 -M 2') );
classifier.buildClassifier(data);
classifier.toString()
ev = weka.classifiers.Evaluation(data);
v(1) = java.lang.String('-t');
v(2) = java.lang.String(filename);
v(3) = java.lang.String('-split-percentage');
v(4) = java.lang.String('66');
prm = cat(1,v(1:4));
ev.evaluateModel(classifier, prm)
Result:
Time taken to build model: 0.04 seconds
Time taken to test model on training split: 0.01 seconds
=== Error on training split ===
Correctly Classified Instances 767 99.2238 %
Incorrectly Classified Instances 6 0.7762 %
Kappa statistic 0.9882
Mean absolute error 0.0087
Root mean squared error 0.0658
Relative absolute error 1.9717 %
Root relative squared error 14.042 %
Total Number of Instances 773
=== Detailed Accuracy By Class ===
TP Rate FP Rate Precision Recall F-Measure MCC ROC Area PRC Area Class
0.994 0.009 0.987 0.994 0.990 0.984 0.999 0.999 Nikon
1.000 0.000 1.000 1.000 1.000 1.000 1.000 1.000 Sony
0.981 0.004 0.990 0.981 0.985 0.980 0.999 0.997 Canon
Weighted Avg. 0.992 0.004 0.992 0.992 0.992 0.988 1.000 0.999
=== Confusion Matrix ===
a b c <-- classified as
306 0 2 | a = Nikon
0 258 0 | b = Sony
4 0 203 | c = Canon
=== Error on test split ===
Correctly Classified Instances 358 89.9497 %
Incorrectly Classified Instances 40 10.0503 %
Kappa statistic 0.8482
Mean absolute error 0.0656
Root mean squared error 0.2464
Relative absolute error 14.8485 %
Root relative squared error 52.2626 %
Total Number of Instances 398
=== Detailed Accuracy By Class ===
TP Rate FP Rate Precision Recall F-Measure MCC ROC Area PRC Area Class
0.885 0.089 0.842 0.885 0.863 0.787 0.908 0.832 Nikon
0.993 0.000 1.000 0.993 0.997 0.995 0.997 0.996 Sony
0.796 0.060 0.841 0.796 0.818 0.749 0.897 0.744 Canon
Weighted Avg. 0.899 0.048 0.900 0.899 0.899 0.853 0.938 0.867
=== Confusion Matrix ===
a b c <-- classified as
123 0 16 | a = Nikon
0 145 1 | b = Sony
23 0 90 | c = Canon
import weka.core.Instances.*
filename = 'C:\Users\Girish\Documents\MATLAB\DRESDEN_NSC.csv';
loader = weka.core.converters.CSVLoader();
loader.setFile(java.io.File(filename));
data = loader.getDataSet();
data.setClassIndex(data.numAttributes()-1);
%% classification
classifier = weka.classifiers.trees.J48();
classifier.setOptions( weka.core.Utils.splitOptions('-C 0.1 -M 1') );
classifier.buildClassifier(data);
classifier.toString()
ev = weka.classifiers.Evaluation(data);
v(1) = java.lang.String('-t');
v(2) = java.lang.String(filename);
v(3) = java.lang.String('-split-percentage');
v(4) = java.lang.String('66');
prm = cat(1,v(1:4));
ev.evaluateModel(classifier, prm)
Result:
Time taken to build model: 0.04 seconds
Time taken to test model on training split: 0 seconds
=== Error on training split ===
Correctly Classified Instances 767 99.2238 %
Incorrectly Classified Instances 6 0.7762 %
Kappa statistic 0.9882
Mean absolute error 0.0087
Root mean squared error 0.0658
Relative absolute error 1.9717 %
Root relative squared error 14.042 %
Total Number of Instances 773
=== Detailed Accuracy By Class ===
TP Rate FP Rate Precision Recall F-Measure MCC ROC Area PRC Area Class
0.994 0.009 0.987 0.994 0.990 0.984 0.999 0.999 Nikon
1.000 0.000 1.000 1.000 1.000 1.000 1.000 1.000 Sony
0.981 0.004 0.990 0.981 0.985 0.980 0.999 0.997 Canon
Weighted Avg. 0.992 0.004 0.992 0.992 0.992 0.988 1.000 0.999
=== Confusion Matrix ===
a b c <-- classified as
306 0 2 | a = Nikon
0 258 0 | b = Sony
4 0 203 | c = Canon
=== Error on test split ===
Correctly Classified Instances 358 89.9497 %
Incorrectly Classified Instances 40 10.0503 %
Kappa statistic 0.8482
Mean absolute error 0.0656
Root mean squared error 0.2464
Relative absolute error 14.8485 %
Root relative squared error 52.2626 %
Total Number of Instances 398
=== Detailed Accuracy By Class ===
TP Rate FP Rate Precision Recall F-Measure MCC ROC Area PRC Area Class
0.885 0.089 0.842 0.885 0.863 0.787 0.908 0.832 Nikon
0.993 0.000 1.000 0.993 0.997 0.995 0.997 0.996 Sony
0.796 0.060 0.841 0.796 0.818 0.749 0.897 0.744 Canon
Weighted Avg. 0.899 0.048 0.900 0.899 0.899 0.853 0.938 0.867
=== Confusion Matrix ===
a b c <-- classified as
123 0 16 | a = Nikon
0 145 1 | b = Sony
23 0 90 | c = Canon
Same Result with both split options which is the result for default options i.e. -C 0.25 -M 2 for J48 classifier
please help!!! stuck here for a long time.Tried Different means but nothing worked for me

Netlogo BehaviourSpace weird Output and Multiple Runs

For some weird reason the behaviorSpace in netlogo runs the same value pairs model multiple times even though repetitions are 1. I can't understand why. The output file in table format looks like this. I don't know what's up with double quotes.
BehaviorSpace results (NetLogo 5.2.0)
/home/abhishekb/new_models/basic/try4.nlogo
experiment1
10/26/2015 02:34:28:770 +0530
min-pxcor max-pxcor min-pycor max-pycor
-7 7 -7 7
[run number] knt k threshold scale [step]
16 0 75 0.1 1 2535
7 0 54 0.1 1 0 8715
5 0 47 0.3 1 0 9374
10 0 61 0.1 1 0 8841
"22 0 89 0.1 1 0 3664"8" 0 54 0.3 1 0 12001" 0 40 0.1 1 0 10727
2" 013" 0 68 0.1 1 0"22 0 89 0.1 1 0 4449
128" 0 103 0.1 1 0 2805
4 0 47 0.1 1 0 1200119" 0 82 0.1 1 0 12001"1 0 40 0.1 1 0 12001
3"
26" 0 96 0.3 1 0 4800
9" 0 103 0.3 1 0 43321" 0 82 0.6 1 0 7385
31 0 110 0.1 1 0 2976
1" 0 40 0.1 1 0 12001
4" 0 89 0.6 1 0 6389
25 0 96 0.1 1 0 7517
26 0 96 0.3 1 0 5479
9""27" 0 96 0.6 1 0 6117
28 0 103 0.1 1 0 2219
29 0 103 0.3 1 0 6411
30 0 103 0.6 1 0 5693
31 0 110 0.1 1 0 3985
78 500 61 0.6 1 0 9720
79 500 68 0.1 1 0 6067
80 500 68 0.3 1 0 6795
81 500 68 0.6 1 0 8305
82 500 75 0.1 1 0 4416
83 500 75 0.3 1 0 5742
84 500 75 0.6 1 0 7399
85 500 82 0.1 1 0 5306
86 500 82 0.3 1 0 5388
01"
87 500 82 0.6 1 0 6869
88 500 89 0.1 1 0 12001
89 500 89 0.3 1 0 5097
90 500 89 0.6 1 0 6478
91 500 96 0.1 1 0 2275
92 500 96 0.3 1 0 4693" 500 96 0.6 1 0 6395
94"94 500 103 0.1 1 0 12001
95 500 103 0.3 1 0 3984
96 500 103 0.6 1 0 5440
97 500 110 0.1 1 0 1893
98 500 110 0.3 1 0 37299" 500 110 0.6 1 0 5275
100 750 40 0.1 1 0 12001
101" 750 40 0.3 1 0 12001
102 750 40 0.6 1 0 12001
"
103""" 750 47 0.1 1 0 11911
"
104""" 750 47 0.3 1 0 12001
105 750 47 0.6 1 0 11821
750" 54 0.1 1 0 12001
107 750 54 0.3 1 0 8703
811108" 750 54 0.6 1 0 10099
5"
,61" 0.1 1 0 12001
110 750 61 0.3 1 0 7453
0111" 750111" 750 61 0.6 1 0 9051
112 750 68 0.1 1 0 12001
68 0.3 1 0 12001
BehaviourSpace Code:
##$###$##
NetLogo 5.2.1
##$###$##
##$###$##
##$###$##
<experiments>
<experiment name="experiment1" repetitions="1" runMetricsEveryStep="false">
<setup>check-setup-percent
file-write-values</setup>
<go>go</go>
<final>write-to-file</final>
<timeLimit steps="12000"/>
<exitCondition>count inboxturtles with[exit = 1 and exited = false] = 0</exitCondition>
<steppedValueSet variable="knt" first="0" step="250" last="2500"/>
<steppedValueSet variable="k" first="40" step="7" last="110"/>
<enumeratedValueSet variable="threshold">
<value value="0.1"/>
<value value="0.3"/>
<value value="0.6"/>
</enumeratedValueSet>
<enumeratedValueSet variable="scale">
<value value="1"/>
</enumeratedValueSet>
</experiment>
</experiments>
##$###$##
##$###$##
default
0.0
-0.2 0 0.0 1.0
0.0 1 1.0 0.0
0.2 0 0.0 1.0
link direction
true
0
Line -7500403 true 150 150 90 180
Line -7500403 true 150 150 210 180
##$###$##
1
##$###$##

predict value of curve in matlab

Suppose I have the following vector of points:
X=[ 0.401 0.398 0.395 0.392 0.388 0.384 0.381 0.377 0.373 0.368 0.364 0.359 0.354 0.349 0.344 0.339 0.334 0.328 0.322 0.316 0.310 0.304 0.297 0.291 0.284 0.277 0.270 0.263 0.256 0.249 0.242 0.234 0.227 0.220 0.212 0.205 0.198 0.190 0.183 0.176 0.169 0.161 0.154 0.147 0.140 0.134 0.127 0.120 0.113 0.107 0.101 0.094 0.088 0.082 0.076 0.070 0.064 0.059 0.053 0.048 0.042 0.037 0.032 0.027 0.022 0.018 0.013 0.009 0.004 0.000 -0.004 -0.008 -0.012 -0.016 -0.019 -0.023 -0.026 -0.030 -0.033 -0.036 -0.039 -0.042 -0.045 -0.048 -0.050 -0.053 -0.055 -0.058 -0.060 -0.062 -0.064 -0.066 -0.068 -0.070 -0.072 -0.074 -0.076 -0.077 -0.079 -0.080];
Y=[0.347 0.362 0.377 0.393 0.409 0.426 0.442 0.459 0.477 0.494 0.512 0.530 0.548 0.567 0.585 0.604 0.622 0.641 0.659 0.678 0.696 0.715 0.733 0.750 0.768 0.785 0.801 0.817 0.833 0.848 0.863 0.876 0.890 0.902 0.914 0.925 0.935 0.945 0.953 0.961 0.969 0.975 0.981 0.986 0.990 0.993 0.996 0.998 0.999 1.000 1.000 0.999 0.998 0.996 0.994 0.991 0.988 0.984 0.979 0.974 0.969 0.963 0.957 0.951 0.944 0.937 0.930 0.922 0.914 0.906 0.898 0.889 0.881 0.872 0.863 0.855 0.846 0.837 0.827 0.818 0.809 0.800 0.791 0.782 0.773 0.764 0.755 0.747 0.738 0.729 0.721 0.712 0.704 0.696 0.688 0.680 0.672 0.664 0.656 0.649];
When I plot the points X and Y, this is what I get:
I want to calculate the value of 'Width' of the curve W. How can I do that?
It looks like the points are unordered, and so simply subtracting the last point by the first point won't work. What you can do is use max and min on the X array to determine the width:
Width = max(X) - min(X);
It's certainly as simple as that! FWIW, your title says one thing, but your question asks another. Suggest you either edit your question or title for clarity.

Set colorbar ranges in 3d graph in matlab

I would like to create a three dimensional surface using this:
>> a=X
a =
Columns 1 through 8
0 50 100 150 200 250 300 350
Columns 9 through 16
400 450 500 550 600 650 700 750
Columns 17 through 21
800 850 900 950 1000
>> b=Y
b =
0
50
100
150
200
250
300
350
400
>> c=Z
c =
Columns 1 through 8
0 0 0 0 0 0 0 0
16 32 67 98 127 164 194 234
120 171 388 773 1086 1216 1770 2206
189 270 494 1978 2755 3134 5060 10469
133 166 183 348 647 937 1446 2304
192 162 154 113 161 189 266 482
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
Columns 9 through 16
0 0 0 0 0 0 0 0
366 604 529 504 346 226 228 179
4027 11186 10276 5349 2560 1322 996 799
27413 76387 37949 15591 5804 2654 1803 1069
9844 24152 14772 4613 1777 849 459 290
1288 2623 1538 582 280 148 90 56
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
Columns 17 through 21
0 0 0 0 0
108 94 79 0 0
646 476 612 0 0
884 858 722 0 0
266 215 139 0 0
48 48 31 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
>> surf(X,Y,Z)
At the same time I would like to define that Z values < = 1803 will be shown with red color on the surface graph, 1803 < Z < 2755 yellow and Z > = 2755 green. The limits of the colorbar can be the min and max values of Z (from 0 to 76387). How can I set the ranges of the colorbar in order to get this result?
This will do as you ask:
%# add red (row 1), yellow (row 2), green (row 2)
map = [1 0 0; 0 1 1; 0 1 0];
%# set the new map as the current map
colormap(map);
colors = zeros(size(c)); %# create colors array
colors(c <= 1803) = 1; %# red (1)
colors(c > 1803 & c < 2755) = 2; %# yellow (2)
colors(c >= 2755) = 3; %# green (3)
%# and pass it into surf
surf(a,b,c, colors)