How to illustrate large data using bar plot or other styles? - matlab

I have a set of data and want to plot them. However I don't know how to plot them nicely. I tried to use bar plot in Matlab and the resulted plot is not readable.
I thought to ask if there is a setting or even a new style to plot my results in a better way.
There are 15 bars for each element of x axis [1:19].
Here you can see the required data:
DAT=...
[2.476 4.142 0.000 4.302 4.302 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
6.680 8.703 2.611 6.680 6.680 3.261 0.000 3.799 6.680 0.000 0.000 0.000 0.000 0.000 0.000
7.672 6.498 7.809 7.809 7.809 6.615 5.062 7.809 7.809 3.916 5.895 7.809 2.780 5.195 2.385
27.126 17.441 11.386 0.000 0.000 17.435 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
0.085 0.156 0.284 0.284 0.284 0.000 0.284 0.284 0.284 0.226 0.284 0.284 0.284 0.284 0.284
10.688 12.159 10.688 10.688 10.688 10.688 10.073 5.633 10.688 0.000 0.000 6.681 0.000 0.000 0.000
11.002 11.020 11.002 11.002 11.002 11.002 11.002 9.456 11.002 5.459 2.434 3.585 3.527 2.160 0.117
2.111 2.111 2.111 2.111 2.111 2.111 2.111 0.000 0.000 2.111 2.111 0.000 0.000 0.581 0.000
9.085 9.906 9.085 1.256 9.085 9.085 9.085 7.299 0.000 9.085 0.000 0.000 0.000 0.000 0.000
3.661 3.661 3.661 3.661 3.661 3.661 3.661 0.000 0.000 1.206 0.000 0.000 0.000 0.000 0.000
3.307 3.703 3.307 2.968 3.307 3.307 3.307 0.000 0.000 3.307 0.000 0.000 0.000 0.000 0.000
4.136 4.123 4.123 4.123 4.123 4.123 4.123 4.123 0.000 4.123 4.123 0.000 3.350 0.000 0.000
2.993 3.000 2.993 2.993 2.993 2.993 0.000 1.134 0.000 2.993 0.000 0.000 1.938 0.000 0.000
1.857 1.864 1.857 1.857 1.857 1.857 1.857 1.857 0.000 1.857 1.857 0.016 1.857 0.704 0.000
3.754 3.754 3.754 3.754 3.754 3.754 3.754 0.000 0.000 3.754 3.754 0.000 0.000 0.000 0.000
2.752 2.760 2.752 2.752 2.752 2.752 2.752 2.752 0.000 2.752 2.752 2.752 2.752 2.752 0.000
3.788 5.611 3.788 3.788 3.788 3.788 3.788 3.369 0.000 3.788 3.788 0.000 3.788 0.000 0.000
0.132 0.123 0.123 0.123 0.132 0.123 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
15.465 14.081 12.468 4.808 1.787 12.858 11.067 3.644 9.317 11.846 10.631 4.233 8.394 5.094 4.225];
bar(DAT)

Try out bar3(DAT)
Output graph:

Related

How to decode .Bin that looks like this?

I have some data from SOILMASTER software that are saved in .Bin format. The program can read them, but when I try to put them into notepad, this shows up...
kPa N N mm mm 5.4 -1.0 -1.0 -0.013 0.000 4.0 -1.0 -1.0 -0.012 0.000 4.0 -1.0 -1.0 -0.012 0.000 *0 4.0 -1.0 -1.0 -0.012 0.000 8# 4.3 -1.0 -1.0 -0.012 0.000 FP 4.3 -1.0 -1.0 -0.013 0.000 T` 4.1 -1.0 -1.0 -0.012 0.000 bp 4.2 -1.0 -1.0 -0.012 0.000 p€ 4.1 -1.0 -1.1 -0.012 0.000
~ 4.2 -1.0 -1.1 -0.012 0.000
Ś  4.3 -1.0 -1.0 -0.012 0.000 š° 4.0 -1.0 -1.0 -0.012 0.000
the same type of data should look like this...
mins mins kPa N N mm mm
1 00:00:00:00 0.000 5.3 -1.0 -1.0 0.012 0.000
2 00:00:00:03 0.060 4.1 -1.0 -1.0 0.012 0.000
3 00:00:00:07 0.120 4.2 -1.0 -1.0 0.016 0.000
4 00:00:00:10 0.180 4.1 -1.0 -1.0 0.019 0.000
5 00:00:00:14 0.240 4.1 -1.0 -1.0 0.021 0.000
I tried to go through some decoders online and tried the encoding formats in notepad++ and nothing worked. Is there some process that can decode them? It would help a lot.
Thank you for your time.
Tom

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.

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.

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

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

Extra, changing character in output file MATLAB fprintf

I have two data structures:
atomName <855*1 cell>
atomSASA <855*1 double>
which I am using in code to produce an output file:
%write out SASA values for individual atoms to file
results_file = fopen('output.txt','w');
fprintf(results_file,'SASA for Individual Atoms: \n');
i=1;
while i < (855)
fprintf(results_file,'Atom %s %s: %.3f\n',i,cell2mat(atomName(i)),atomSASA(i));
i = i + 1;
end
The file seems correct for the first 32 lines, but starting at line 33, there is an extra character after the word Atom. The character changes each line, eventually going through digits, capital letters A-Z, lower letters a-z etc. I would like to remove this extra character from each line:
Atom ! HG23: 6.286
Atom " N: 0.000
Atom # CA: 0.000
Atom $ C: 0.000
Atom % O: 0.000
Atom & CB: 0.000
Atom ' CG: 0.000
Atom ( CD1: 0.000
Atom ) CD2: 0.000
Atom * CE1: 0.000
Atom + CE2: 0.000
Atom , CZ: 0.000
Atom - OH: 0.000
Atom . H: 0.000
Atom / HA: 0.000
Atom 0 HB2: 0.000
Atom 1 HB3: 0.000
Atom 2 HD1: 0.000
Atom 3 HD2: 0.000
Atom 4 HE1: 0.000
Atom 5 HE2: 0.000
Atom 6 HH: 0.000
Atom 7 N: 0.000
Atom 8 CA: 0.000
Atom 9 C: 0.000
Atom : O: 0.000
Atom ; CB: 0.000
Atom < CG: 0.000
Atom = CD: 0.000
Atom > CE: 1.208
Atom ? NZ: 1.312
Atom # H: 0.000
Atom A HA: 0.000
Atom B HB2: 0.000
Atom C HB3: 0.000
Atom D HG2: 0.000
Atom E HG3: 0.000
Atom F HD2: 0.000
Atom G HD3: 0.000
Atom H HE2: 0.000
Atom I HE3: 33.979
Atom J HZ1: 0.000
Atom K HZ2: 0.000
Atom L HZ3: 44.513
Atom M N: 0.000
Atom N CA: 0.000
Atom O C: 0.000
Atom P O: 0.000
Atom Q CB: 0.000
Atom R CG: 0.000
Atom S CD1: 0.000
Atom T CD2: 0.000
Atom U H: 0.000
Atom V HA: 0.000
Atom W HB2: 0.000
Atom X HB3: 0.000
Atom Y HG: 0.000
Atom Z HD11: 0.000
Atom [ HD12: 0.000
Atom \ HD13: 0.000
Atom ] HD21: 0.000
Atom ^ HD22: 0.000
Atom _ HD23: 0.000
Atom ` N: 0.000
Atom a CA: 0.000
Atom b C: 0.000
Atom c O: 0.000
Atom d CB: 0.000
Atom e CG1: 0.000
Atom f CG2: 0.000
You should probably replace your fprintf by:
fprintf(results_file,'Atom %i %s: %.3f\n', i, atomName{i}, atomSASA(i));
To print an integer, you should use %i or %d, with %s an integer gets interpreted as an ascii value:
>> fprintf('as ascii: %s\n', 66)
as ascii: B
>> fprintf('as number: %i\n', 66)
as number: 66
One other thing: it is easier to write atomName{i} instead of cell2mat(atomName(i)). Indexing a cell array with curly braces gives you the content of the i-th cell, what you want. Indexing it with normal parenthesis will give you a 1x1 cell array with the content of the i-th cell:
>> atoms = {'aa','bb','cc'}
atoms =
'aa' 'bb' 'cc'
>> class(atoms{2})
ans =
char
>> class(atoms(2))
ans =
cell
See the manual.