I am trying to load an ASCII files that contains a points which are not defined in the 2nd colomns in certain lines, I am doing so and getting this error:
S = load('bond_order_correlation4A.dat')
??? Error using ==> load
Unknown text on line number 7 of ASCII file
C:\Users\VAIO\Desktop\MATLAB\R2010b\bin\bond_order_correlation4A.dat
"-nan+-nani".
How can I avoid this error, in other way how can I skip reading the lines that have a NaN?
Any ideas?
here are the lines of the data:
1.751500e+01 0.900636+0.000000i
1.854500e+01 0.910675+0.000000i
1.957500e+01 0.901020+0.000000i
2.060500e+01 0.866812+0.000000i
2.163500e+01 0.826753+0.000000i
2.266500e+01 0.736222+0.000000i
2.369500e+01 -nan+-nani
2.472500e+01 -nan+-nani
2.575500e+01 -nan+-nani
2.678500e+01 -nan+-nani
2.781500e+01 -nan+-nani
2.884500e+01 0.804500+0.000000i
2.987500e+01 0.863660+0.000000i
3.090500e+01 0.899600+0.000000i
3.193500e+01 0.912361+0.000000i
3.296500e+01 0.906553+0.000000i
3.399500e+01 0.883229+0.000000i
3.502500e+01 0.873248+0.000000i
3.605500e+01 0.903132+0.000000i
3.708500e+01 0.909807+0.000000i
3.811500e+01 0.904406+0.000000i
3.914500e+01 0.886968+0.000000i
4.017500e+01 0.860080+0.000000i
4.120500e+01 0.810715+0.000000i
4.223500e+01 -nan+-nani
4.326500e+01 -nan+-nani
4.429500e+01 -nan+-nani
4.532500e+01 0.812973+0.000000i
4.635500e+01 0.863783+0.000000i
4.738500e+01 0.895398+0.000000i
4.841500e+01 0.908204+0.000000i
4.944500e+01 0.908985+0.000000i
5.047500e+01 0.900171+0.000000i
5.150500e+01 0.882722+0.000000i
5.253500e+01 0.851140+0.000000i
5.356500e+01 0.890132+0.000000i
5.459500e+01 0.904564+0.000000i
5.562500e+01 0.908607+0.000000i
5.665500e+01 0.904241+0.000000i
5.768500e+01 0.891706+0.000000i
5.871500e+01 0.875118+0.000000i
5.974500e+01 0.844325+0.000000i
6.077500e+01 0.848961+0.000000i
6.180500e+01 0.883005+0.000000i
6.283500e+01 0.900617+0.000000i
6.386500e+01 0.907607+0.000000i
6.489500e+01 0.903102+0.000000i
6.592500e+01 0.903907+0.000000i
6.695500e+01 0.905971+0.000000i
6.798500e+01 0.901497+0.000000i
6.901500e+01 0.891710+0.000000i
7.004500e+01 0.873431+0.000000i
7.107500e+01 0.857750+0.000000i
7.210500e+01 0.892680+0.000000i
7.313500e+01 0.905379+0.000000i
7.416500e+01 0.907424+0.000000i
7.519500e+01 0.904534+0.000000i
7.622500e+01 0.891604+0.000000i
7.725500e+01 0.874679+0.000000i
7.828500e+01 0.880488+0.000000i
7.931500e+01 0.899794+0.000000i
8.034500e+01 0.908564+0.000000i
8.137500e+01 0.906300+0.000000i
8.240500e+01 0.898721+0.000000i
8.343500e+01 0.895449+0.000000i
8.446500e+01 0.900390+0.000000i
8.549500e+01 0.901614+0.000000i
8.652500e+01 0.896143+0.000000i
8.755500e+01 0.884075+0.000000i
8.858500e+01 0.860837+0.000000i
8.961500e+01 0.845785+0.000000i
9.064500e+01 0.883891+0.000000i
9.167500e+01 0.902221+0.000000i
9.270500e+01 0.905519+0.000000i
9.373500e+01 0.901589+0.000000i
9.476500e+01 0.892879+0.000000i
9.579500e+01 0.896607+0.000000i
9.682500e+01 0.900943+0.000000i
9.785500e+01 0.904287+0.000000i
9.888500e+01 0.901320+0.000000i
9.991500e+01 0.892640+0.000000i
1.009450e+02 0.884730+0.000000i
1.019750e+02 0.888384+0.000000i
1.030050e+02 0.895942+0.000000i
1.040350e+02 0.894981+0.000000i
1.050650e+02 0.887988+0.000000i
1.060950e+02 0.874380+0.000000i
1.071250e+02 0.853539+0.000000i
1.081550e+02 0.839207+0.000000i
1.091850e+02 0.867059+0.000000i
1.102150e+02 0.890265+0.000000i
1.112450e+02 0.899481+0.000000i
1.122750e+02 0.903685+0.000000i
1.133050e+02 0.899493+0.000000i
1.143350e+02 0.895112+0.000000i
1.153650e+02 0.896775+0.000000i
1.163950e+02 0.893841+0.000000i
1.174250e+02 0.885450+0.000000i
1.184550e+02 0.874641+0.000000i
1.194850e+02 0.871421+0.000000i
enter code here
You could start by substituting "-nan+-nani" in your data file with "NaN" so that MATLAB can read it correctly, and then as #juampa said, filter out the "NaN" values however you want in MATLAB.
To perform the substitution quickly and easily, I highly recommend vim. Just open the data file in vim and type:
:%s/-nan+-nani/NaN/g
This will do a global substitution, replacing "-nan+-nani" with "NaN" everywhere in the file without asking to confirm each one. If you want to confirm then change the above line to:
:%s/-nan+-nani/NaN/gc
MATLAB should be able to read the file and handle the "NaN" values as NaN.
For MatLab, substitute those strings by nan, or NaN (case insensitive), and it will import them correctly as NaN. Later you can filter them easily within the MatLab runtime
M(find(M) == NaN,:) = []
Related
I am trying to read from a file and display the data in rows 6, 11, 111 and 127 in Matlab. I could not figure out how to do it. I have been searching Matlab forums and this platform for an answer. I used fscanf, textscan and other functions but they did not work as intended. I also used a for loop but again the output was not what I wanted. I can now only read one row and display it. Simply I want to display all of them(data in rows given above) at the same time. How can I do that?
matlab code
n = [0 :1: 127];
%% Problem 1
figure
x1 = cos(0.17*pi*n)
%it creates file and writes content of x1 to the file
fileID = fopen('file.txt','w');
fprintf(fileID,'%d \n',x1);
fclose(fileID);
%line number can be changed in order to obtain wanted values.
fileID = fopen('file.txt');
line = 6;
C = textscan(fileID,'%s',1,'delimiter','\n', 'headerlines',line-1);
celldisp(C)
fclose(fileID);
and this is the file
1
8.607420e-01
4.817537e-01
-3.141076e-02
-5.358268e-01
-8.910065e-01
-9.980267e-01
-8.270806e-01
-4.257793e-01
9.410831e-02
5.877853e-01
9.177546e-01
9.921147e-01
7.901550e-01
3.681246e-01
-1.564345e-01
-6.374240e-01
-9.408808e-01
-9.822873e-01
-7.501111e-01
-3.090170e-01
2.181432e-01
6.845471e-01
9.602937e-01
9.685832e-01
7.071068e-01
2.486899e-01
-2.789911e-01
-7.289686e-01
-9.759168e-01
-9.510565e-01
-6.613119e-01
-1.873813e-01
3.387379e-01
7.705132e-01
9.876883e-01
9.297765e-01
6.129071e-01
1.253332e-01
-3.971479e-01
-8.090170e-01
-9.955620e-01
-9.048271e-01
-5.620834e-01
-6.279052e-02
4.539905e-01
8.443279e-01
9.995066e-01
8.763067e-01
5.090414e-01
-4.288121e-15
-5.090414e-01
-8.763067e-01
-9.995066e-01
-8.443279e-01
-4.539905e-01
6.279052e-02
5.620834e-01
9.048271e-01
9.955620e-01
8.090170e-01
3.971479e-01
-1.253332e-01
-6.129071e-01
-9.297765e-01
-9.876883e-01
-7.705132e-01
-3.387379e-01
1.873813e-01
6.613119e-01
9.510565e-01
9.759168e-01
7.289686e-01
2.789911e-01
-2.486899e-01
-7.071068e-01
-9.685832e-01
-9.602937e-01
-6.845471e-01
-2.181432e-01
3.090170e-01
7.501111e-01
9.822873e-01
9.408808e-01
6.374240e-01
1.564345e-01
-3.681246e-01
-7.901550e-01
-9.921147e-01
-9.177546e-01
-5.877853e-01
-9.410831e-02
4.257793e-01
8.270806e-01
9.980267e-01
8.910065e-01
5.358268e-01
3.141076e-02
-4.817537e-01
-8.607420e-01
-1
-8.607420e-01
-4.817537e-01
3.141076e-02
5.358268e-01
8.910065e-01
9.980267e-01
8.270806e-01
4.257793e-01
-9.410831e-02
-5.877853e-01
-9.177546e-01
-9.921147e-01
-7.901550e-01
-3.681246e-01
1.564345e-01
6.374240e-01
9.408808e-01
9.822873e-01
7.501111e-01
3.090170e-01
-2.181432e-01
-6.845471e-01
-9.602937e-01
-9.685832e-01
-7.071068e-01
-2.486899e-01
2.789911e-01
Assuming the file is not exceedingly large, the simplest way would probably be read the entire file & index the output to your desired lines.
line = [6 11 111 127];
fileID = fopen('file.txt');
C = textscan(fileID,'%s','delimiter','\n');
fclose(fileID);
disp(C{1}(line))
I'm quite new with Matlab and I've been searching, unsucessfully, for the following issue: I have an unstructure txt file, with several rows I don't need, but there are a number of rows inside that file that have an structured format. I've been researching how to "load" the file to edit it, but cannot find anything.
Since i don't know if I was clear, let me show you the content in the file:
8782 PROJCS["UTM-39",GEOGC.......
1 676135.67755473056 2673731.9365976951 -15 0
2 663999.99999999302 2717629.9999999981 -14.00231124135486 3
3 709999.99999999162 2707679.2185399458 -10 2
4 679972.20003752434 2674637.5679516452 0.070000000000000007 1
5 676124.87132483651 2674327.3183533219 -18.94794942571912 0
6 682614.20527054626 2671000.0000000549 -1.6383425512446661 0
...........
8780 682247.4593014461 2676571.1515358146 0.1541080392180566 0
8781 695426.98657108378 2698111.6168302582 -8.5039945992245904 0
8782 674723.80100125563 2675133.5486935056 -19.920312922947179 0
16997 3 21
1 2147 658 590
2 1855 2529 5623
.........
I'd appreciate if someone can just tell me if there is the possibility to open the file to later load only the rows starting with 1 to the one starting with 8782. First row and all the others are not important.
I know than manually copy and paste to a new file would be a solution, but I'd like to know about the possibility to read the file and edit it for other ideas I have.
Thanks!
% Now lines{i} is the string of the i'th line.
lines = strsplit(fileread('filename'), '\n')
% Now elements{i}{j} is the j'th field of the i'th line.
elements = arrayfun(#(x){strsplit(x{1}, ' ')}, lines)
% Remove the first row:
elements(1) = []
% Take the first several rows:
n_rows = 8782
elements = elements(1:n_rows)
Or if the number of rows you need to take is not fixed, you can replace the last two statements above by:
firsts = arrayfun(#(x)str2num(x{1}{1}), elements)
n_rows = find((firsts(2:end) - firsts(1:end-1)) ~= 1, 1, 'first')
elements = elements(1:n_rows)
I want to plot data of an ISO_8859_1 encoded file (two columns of numbers). Those are the first 10 data points of the file:
#Pe2
1 0.8000
2 0.8000
3 0.8000
4 0.8000
5 0.8000
6 0.8000
7 0.8000
8 0.8000
9 0.8000
10 0.8000
The original file has 15000 data points. I create this data with MATLAB, specifically setting ISO_8859_1 encoding, so I am sure that that's the encoding. This is a snippet of the matlab code:
slCharacterEncoding('ISO-8859-1'); %Instruction before writing anything to the file.
fprintf(fileID,' %7d %7.4f',Tempo(i),y(i)); %For loop in this instruction
fprintf(fileID,'\r'); %Closing the file
fclose(fileID);
This is the script that I run. This file is encoded with the default Windows txt files encoding:
set encoding iso_8859_1
set terminal wxt size 1000,551
# Line width of the axes
set border linewidth 1.5
# Line styles
set style line 1 lc rgb '#dd181f' lt 1 lw 1 pt 0 # red
# Axes label
set xlabel 'tiempo'
set ylabel 'valor'
plot 'Pe2.txt' with lines ls 1
This is the output of the gnuplot console when I run the script. After that I input "show encoding":
G N U P L O T
Version 4.6 patchlevel 5 last modified February 2014
Build System: MS-Windows 32 bit
Copyright (C) 1986-1993, 1998, 2004, 2007-2014
Thomas Williams, Colin Kelley and many others
gnuplot home: http://www.gnuplot.info
faq, bugs, etc: type "help FAQ"
immediate help: type "help" (plot window: hit 'h')
Terminal type set to 'wxt'
gnuplot> cd 'C:\Example'
gnuplot> load 'script.txt'
"script.txt", line 10: warning: Skipping data file with no valid points
gnuplot> plot 'Pe2.txt' with lines ls 1
^
"script.txt", line 10: x range is invalid
gnuplot> show encoding
nominal character encoding is iso_8859_1
however LC_CTYPE in current locale is Spanish_Spain.1252
gnuplot>
If I open the file, make some change undo the change and save the file, gnuplot plots the file. I guess that it's because it saves it with local encoding which is the one gnuplot uses to read files.
How do I plot files with gnuplot which are not with the local encoding format?
I also have what it seems to be a similar problem when I output a file with VS2010Css. If I don't specifically set the culture with:
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
I am not able to save a file wich gnuplot is able to plot. I believe that this last problem is because of the "," and the "."
In Css I save the files with this:
StreamWriter Writer = new StreamWriter(dir + #"\" + + (k+1) + "_" + nombre + extension);
Writer.WriteLine("#" + (k+1) + "_" + nombre);
Writer.WriteLine();
Writer.WriteLine("{0,32} {1,32}", "#tiempo", "#valor");
for (int i = 0; i < tiempo.GetLength(0); i++)
{
Writer.WriteLine("{0,32} {1,32}", tiempo[i].ToString(), valor[i, k]);
}
Thank you.
Your file has only carriage returns (\r 0xd) as line breaks which doesn't work with gnuplot. You must use only line feed (\n 0xa), but \r\n does also work.
I'm new to Matlab and doing a signal processing project(Speech Recognition). After doing some calculations, I get some values known as MFCC (Mel-Frequency Cepstral Coefficient) in a matrix. I'm now supposed to apply a Gaussian Mixture Model (GMM) distribution using the function gmdistribution.fit(X,k). But I keep getting the error,
X must have more rows than columns.
I don't understand, how can I fix this? I tried doing a transpose of the matrix, but then, I get other errors.
??? Error using ==> gmcluster at 181
Ill-conditioned covariance created at iteration 3.
Error in ==> gmdistribution.fit at 199
[S,NlogL,optimInfo] =...
My MFCC matrix generally has 13 rows and about 50-80 columns.
Any ideas on how to fix this? Should I be using only upto 12 cols at a time? OR what could be an alternate expectation-maximization (EM) algorithm to obtain a maximum likelihood (ML)estimate in Speech recognition?
Here's a sample matrix that I get after extracting the mfcc feature vectors from the speech:
53.19162380493035 53.04536473593154 52.52404588266867 52.76558091790412 53.63907256262721 53.357790132994836 52.73205096524416 52.902995065027056 52.61096061282659 54.15474467851871 53.67444472478125 52.64177726437717 52.51697384592561 52.71137919365186 53.092851922453896 53.16427640450918 54.43019514688636 60.79640902129941 59.84919922646779 63.15389910551327 61.88723594060794 64.74826830389657 64.8349874832628 64.86278444375218 65.76126193531795 65.64589407152897 65.46920375829764 65.69178734432299 65.28831375816117 64.56074008418904 63.4966945660873 63.81859800557705 63.72800219675504 62.48994205815299 62.170438508902436 61.06563184036766 59.13583014975035 58.81335869501639 56.32130498897641 55.13711899166046 54.013505531107796 54.15759852717166 53.44176740036524 53.13219768600348 53.03407270007307 52.88271825256845 53.822163186509016 53.53892778841879 54.04538463287215 59.485371756367954 58.48009762761471 54.643413468895346 52.808848460884654 52.87392859698496 52.42111841679119 53.2365666558251 53.30622484832905 53.1799318016215 53.784807994410315 53.248067707554924 52.69122098296521 52.50131276155125 53.43030515391315 53.902384536061604 54.029570128176985 52.842675820980034 52.79731975873874 53.18695701339912
-10.209801833131205 -9.680631918902254 -9.62767876068187 -11.100788671331799 -12.214764051532008 -10.968305830999338 -9.860973825750351 -9.865056435511548 -10.658715794299441 -9.3596215435813 -11.6646716335442 -11.73183849207276 -12.378134406457027 -10.926012890327158 -11.620321504456165 -10.158285684702548 -9.264017760124812 -3.477686356268614 -3.34008367962826 -4.830538727398767 -2.000396004172366 -4.4851181728969225 -2.9033880784025152 -4.367902167404347 -4.497084603581041 -5.199683464056032 -5.906443970301479 -6.1194300184632855 -5.96250940992931 -6.359811770556116 -6.264817939973589 -4.895405335125048 -5.356838360441918 -6.327382452484718 -6.680325151391659 -6.17848037726304 -5.4759013940523245 -1.9841026636312946 -4.076294540940979 -7.824603409725002 -5.800269620602235 -8.01263214623702 -11.425250071230579 -10.277472714265365 -10.774573945280718 -11.322162485376891 -10.052477908307408 -10.004482396755566 -8.557096237262265 -7.319189335399103 -4.798868632345757 -10.203105092807693 -10.406716632774856 -11.067414745093817 -11.699111553041329 -10.749597806292954 -10.555273429092225 -8.854304279940754 -10.903698849240602 -10.234951031082241 -11.550994106255267 -11.295232804215324 -10.688554946454785 -9.208980407123816 -10.585845595336993 -10.757300448605834 -10.319608162526984 -10.551598424355781
-0.18311276580153307 -1.3000235617058096 -2.379404485976171 0.8537711039288245 0.7835891293988151 -0.786100291329253 1.0107138900981782 -0.12469382941718324 -2.2952791566222173 -0.8251663787748776 -0.050658777310996696 -4.6807361290865295 -3.3756455575107784 0.38895610612101605 -0.9962664893365839 -1.3680101462804826 -0.7328675082528926 14.930618844131613 11.172961105935304 16.974801313922335 13.375385369069916 14.024700863057664 14.594849346714536 17.610029847404075 16.601731375214815 15.581203919095396 15.429198596491359 15.842389728372694 16.162847697063377 17.262648834400064 18.2608582394078 19.38844125300681 16.858591012785013 16.93154670795065 12.906259456599424 13.056739996060314 11.258250889980491 8.834726263239137 6.184939770895715 4.068236554570518 2.184520358080839 3.6716311416454106 0.5890504959921528 -3.0455374126328874 -1.657407892408495 0.33660057466143056 -0.40801030148804557 0.04270808730635576 3.208411924734062 5.821481390407001 4.560967865706884 -0.9575473658761547 -1.9690622742411314 -1.4335363449433605 0.5073073427521086 1.8313651620152203 -2.1659200593772345 1.2769675752335854 -2.2873258303700696 -0.030049578085935582 -2.002440722711317 -2.3424337647822346 -4.259810095095228 -0.9747655920995262 0.09482704525635513 -0.2885341356828254 1.439149953470075 0.6807611595304401
2.087244713218005 -3.787403802296573 -4.665688240227797 0.46022874550890147 -0.16943798737784035 -2.7170563621342785 -1.7464303367036695 -3.27442943105816 -3.6318990907200597 -1.1574346481702122 -1.0207450052082863 -5.838249114276465 -4.864029691290982 -2.7443279494466704 -1.3475670289669839 -0.71926223394222 -1.7145131082739746 10.695036462762722 10.398176627688748 11.642258160333318 8.67660434911699 13.223576542483247 14.470121526018994 14.100543157086074 13.22291384069529 11.67823582796623 13.466476916853203 13.535357097626715 14.875339057135838 14.37083096189283 13.33673313953938 12.329553090328996 9.676373050790103 11.448653427990415 9.874926564656558 7.147530590070999 10.29584390330658 10.101141207939456 5.283325337013565 4.507665609590605 3.1555597807254223 1.176891149051998 -0.2017066100725112 -2.5074705794245427 3.7132131484813073 0.9607407688505634 -3.2742739297063865 -6.602070936837743 -2.2912280318564378 10.190482148210974 10.157945177713376 -0.09147003586407224 -5.244432802624313 -1.2872483780850776 -3.7378553488851147 2.853534940706138 -2.9599246290596257 -1.2759697907404983 -2.609173347676013 -0.027021884588768103 -2.3092682012995387 -1.4002697262020989 -4.192442987678205 -0.11708538059933485 -1.722764980370641 -0.8528543327485958 0.36818682029243044 -1.5833959315094956
-1.2340033668089612 -2.7554310519289933 1.4704457874837413 -0.4125243211298726 1.7297567688324673 3.721374587353874 -2.2232745236466402 -1.0295891117338212 1.021098021933131 -3.392544522126444 1.3301447592375433 -0.30182589581098784 -2.2645887723031413 0.5179073904608001 2.0537130718040917 -3.030349632233867 -2.107849434880047 -7.949976055283274 -5.172658838436902 -7.2904509401269575 -6.1323858833603815 -2.37546696444418 -2.6620539778383723 -3.5795807500300305 -4.687709564035536 -1.7454933814935076 -0.6827757483935794 0.23687223893178067 2.8267871613253077 3.5866135581831227 3.142665641927276 4.095262325494299 3.871285159350548 3.8703187080829764 3.8314236250858555 1.798983626211966 0.725468180389042 0.11919814479647405 2.7173707003940124 6.868690477210499 6.270964718280218 2.3176609494750564 2.0733820130334926 -0.8539453920978304 3.48931978155834 -2.6098957232427957 0.7925129692289851 -2.482250690121881 -1.9255950956807195 -3.3296568338000525 -2.5852039200206076 0.7513494304110043 1.6119079892129162 0.8581457406304087 1.4037071284373093 -3.163651849398714 5.052978402873416 2.4518824480379813 0.027602305580521395 0.7477958990121767 0.9232542431737198 -0.5545479544994354 -3.4480660326803503 1.0747263160741485 -4.078097840161742 4.485742151839941 0.1658605159666291 0.1722930547996016
-1.6428664752690114 3.7865726986742145 2.5318491820052564 -2.1947219298888676 -2.1237775233625986 2.598630953202959 -6.076201524281277 -5.315246911864284 -1.5747455209374586 -3.223379488606859 2.6008295264581776 1.3270506534986315 -2.5790744715346676 0.7756431623687378 3.0553271757777356 -0.20800002044634847 -1.530027153710214 -2.207970121996219 -1.8813636939941347 -2.685201388968379 -1.2497372042225408 2.5726591149003712 1.4779209530617206 0.18848939011950389 -0.8737068656038859 4.364271583896629 2.0338276700410187 4.017665258617117 2.929288856255161 10.031463178073729 7.807148474194119 8.930649791195147 9.356704480964387 4.682860624638529 3.9421955431659375 3.46979114616638 0.10907941624689588 1.013539556043216 1.380950812959332 1.077296756517698 4.643176114193134 0.276532579753215 1.3247848485761091 -1.6452351331258643 5.459080479943587 -2.623903958160855 -3.6495250981385525 0.30098983943901886 1.2192582165344557 3.9341748890807207 3.8902438441040768 2.3070835920696586 -2.692501110699399 1.6807838025217028 1.5259881694196216 0.3750392433389195 5.708674336592535 -1.1571072509634228 -1.9909829706185518 -2.911287549300028 -4.934348834333174 -2.258176779559039 0.17624511060134188 0.02295826196619305 -3.516972940169973 5.184345513656031 1.4594074325337887 -0.19794455729474633
2.362306464828889 1.8140886321872307 3.105122487428386 -2.452729932993756 -1.9482153346221507 0.23556664481369372 1.0605939999557794 9.466891504042334 4.485454438679325 2.6792667132201102 -0.7696085536288818 1.1799363148487811 -4.770207147524265 0.7773255533610134 -1.0253054017942649 5.364238239319841 3.1331011184169473 4.744685304867839 -0.052537238369118014 4.477806263589113 3.1539530991186067 6.4185233259645385 2.549990446321861 2.4829837421356564 4.089323590949597 7.9396405004582045 6.041498345508568 9.234608707932582 7.3843205505399885 10.495371462065135 15.043508733932194 8.70736248600434 13.199534350054295 9.807690741908354 9.182134815924455 12.06839623216329 7.974743468866006 12.349726591545481 5.750367027892127 -0.6482940009399485 5.4638120941442185 1.856389413910232 1.9530813300592067 -2.8701346921179733 1.558852931425583 -0.19366384484174437 -2.6386457918474457 1.4662219452543457 2.079641671534525 15.326629935694294 14.705559998054612 -0.06282946858494885 -1.827803410621235 3.114649202395378 0.3720781976421628 0.43011998686353536 -3.376799358785071 -1.5552531679484054 3.060902156478365 3.5360394473034553 -2.3908283396567356 0.6675611086499327 0.22711502816964574 -6.457828495248154 -0.6807474446526474 -0.6230980701736715 2.2692316872172476 -0.979235567032777
2.306823535295793 3.4952484194762055 5.910905884417197 -3.0627994884681873 -3.2217585242174294 -0.015187803494101149 -0.9514287527346498 3.114431724585367 0.42923281798814705 -3.189859804015462 -1.472673603923648 -3.036867739556342 -0.15973786580917693 -0.0905525722541792 2.330382174351248 2.7439958525955515 0.3730263667251821 -12.515523622378907 -13.343548342714616 -11.536760383050373 -8.307383651556634 -15.660481772806875 -14.155076207607415 -14.343032997039627 -11.791205489191787 -14.964231411185601 -13.183950294156357 -8.972526839374074 -5.366478645304655 -10.910217774510665 -1.5480767893424763 -8.888577773693916 -2.6255911360834023 -5.8588628908556695 -4.145564000313309 -2.984375697431632 0.8831077064431804 -5.243824833303439 5.196626588048474 6.352837095147023 1.2112116324076188 -2.9147691775934286 -2.6935780565318352 -2.810972986669758 4.9399646272914275 -1.1703117105056318 -2.402532372315127 -4.8461309660884675 -7.261524451953783 -2.5282219889051856 -1.0065282601086587 -2.5563997598612156 -4.351683980269447 -0.46252498899381495 -5.890633052969005 -0.3032076532083649 -0.6457938679695084 -0.455043482005029 3.359840875612215 -1.7228176367513395 -3.168976094613273 -2.5233843488620917 -6.495499983402964 -3.4972987525688515 0.7115283186290751 -2.581097605905542 0.6315410714331887 0.19502062594451325
1.2870172739850947 2.713157481924801 -0.5205380954882455 -4.658525381198428 -0.10827507866220412 2.4486415136057875 -0.2640204926534809 -0.09970608992954652 1.5082258768440102 -0.48148890836461583 6.911722876338505 -1.839425896561688 -3.841669694063511 -4.524554996776859 -0.9323811218879002 -6.12813923896959 -2.617633134059251 -6.309717724130619 -3.909047191185573 -6.705305972326263 -3.194505292603528 -7.893721876340621 -0.7610949447938617 -0.6090909340423546 1.4581855733113227 -2.41596099072141 -3.8541389118806912 -1.927700181895679 4.665459793274741 -2.132645903487048 4.157947245063189 0.11326683589817262 -1.162075689787945 1.055761599597126 3.298475882289032 0.9391848013866494 5.223274229835592 5.199193224601442 6.24812913948699 5.2190463423872515 1.5179114498579496 -0.6790185492512775 -0.31373376397636593 -3.5993965276962707 4.302535367682559 5.0068035330847005 -2.436072054028143 -0.8350201387276532 -2.018104375721472 0.5404586080558861 -2.428770201558009 -2.335732881592787 -0.052034561490399235 2.6353099398265676 -2.99995676341149 1.7399565653589897 -0.29483744276382473 4.957413374961816 5.6898464888615 -4.002464222625706 0.966133847419872 2.170532357744949 -2.4172124815273173 -5.913083394982123 -0.22652498917043715 0.138040634076645 -2.826152803587723 5.842509989192995
-6.149578124267104 -2.8288721761218962 -0.27284674336933024 -0.7388702321118317 6.111878602550777 3.359125556152289 1.2074835809541602 -2.229103203811113 -1.625118718284933 -0.2004222132512952 2.0932748099429754 0.712406626137792 0.43416711590137985 -5.55554193439384 -2.1786650973628827 -2.969057723871395 -6.618199451327406 2.299416281672153 5.007013248892597 -2.8033104103688027 -0.14925301159195922 -3.1533724522208697 -1.686316186073986 -0.08884837954280254 1.3265208802169017 1.3523930289041641 3.5524134648371395 -1.4254466520590146 -3.5611240333626477 1.0329276937146186 0.753052597154297 0.7975894394949765 -1.1854014340942607 1.1593797963914545 -0.8529267167794818 -5.171015036219429 4.116322136411159 -1.4483994704782983 -4.286164521201809 2.740046108799948 -3.5798763236060673 -3.018292657641495 -3.1806602684198966 -7.234273046469597 -9.434807181114692 -1.5847563989433828 -3.5635243742856346 4.782665786942992 3.5778211425622497 1.6853638633605281 1.7167799803768633 -1.6174055012561088 3.7435401900571574 -3.176593678259591 6.40495736593622 3.3331406463423483 -4.189245091250336 -1.1362166265192732 4.592859698246665 -2.8863334811724606 0.16041676401714375 4.737837256397985 -2.2744510630052366 1.4695485402180768 -4.897075450622638 1.0194864096015128 3.0757846367935398 1.489203230013674
-5.616870225243653 4.10940999519677 -0.3567822711722583 4.987855490462697 2.5632059692246143 -4.705396196410884 -0.1194996962733683 8.46869233605413 1.7788275688487483 -1.9527299063266377 -1.481085011956697 -1.0244613136295895 3.2992905241167114 -3.64385218716246 0.4426619512128128 -0.9239334997116153 -1.8620760850713798 -1.572039531941818 -10.036763755809012 -4.991528131941471 -7.136095340914314 -3.9318863449619683 -8.239368103131268 -8.443697887490892 -7.638579800501108 -8.460278636486919 2.042450826339361 -2.9885807367329646 -7.09364471308204 0.751496922690038 -0.7845673603407124 3.01935526513198 -1.39022538332522 -1.3101410638362037 -6.557786354682332 -10.172228179790066 -7.914321004354581 -5.649458806929109 2.0908760762554857 -1.4736963383710477 -1.1834278800206155 -0.6892124083994282 4.710875739605662 -3.269448539379895 -1.365967094144594 2.229881555767406 -0.9419137895352326 -0.48671864439322476 4.178896930726449 -6.953289505262448 -3.5225552311666406 -0.03841148260907753 0.14013269702442782 -6.512368259808616 1.8280649782849192 0.3454330974085145 -7.766620058704248 1.6650823954773208 9.615187994533223 3.360235349725343 0.22182808924480077 -0.30209172650913635 -1.6349262462057823 5.754809401078592 -1.6377375938940244 4.58705098784457 -2.404590707062002 0.45319882935997813
-3.730821551088958 1.1493694300690667 6.12342052964259 1.0160737493461047 4.543231805847945 -0.46099872305259204 -1.5594323941163388 10.090773095751917 5.028250117132579 1.5903687490782517 0.5749808655709501 -4.492674335179201 2.325703447395548 5.206408565021089 -4.9872461967223565 -6.549149325309605 2.90139977554803 -3.116490551862926 -8.703818668102071 -0.6313375630613844 -1.3155034176934333 1.1556044127857454 -0.9275062964334158 2.1324193244502876 3.430145051864411 4.086699745467884 5.480203425684989 1.3741912885959398 3.339835767680544 5.640295156144797 1.9610369474663063 1.785080274117643 1.8291947445479142 2.966205980470809 -0.12596430958161875 4.646073914100102 -0.7648039700071241 6.3484330647888605 4.459704396949977 1.5062484187054803 -1.6168718590653306 1.7558262745105164 1.2355091938620948 -9.312287204368275E-4 -0.5174901532050828 -3.0942917590395123 2.127834965233185 2.205667503405521 1.120114080459297 -1.7595270682165296 -9.083346980110788 -1.4981626322158839 0.7146008123272161 -0.6811098332417078 0.32703395934824275 -2.555380698176684 1.7740823756697832 4.5707670000209495 1.4842964294571344 4.818614788487457 3.1215801329358515 1.4479667080737233 1.1758507462380035 6.03230783411774 2.288914057777 4.82860171466599 -1.2457175363287405 -0.5058301430711261
-2.768473705667538 0.15564719507110275 -2.6550122323991947 -5.709488621527887 0.4785386384778287 0.6814858260993006 -5.52429514744985 -0.5602195429716864 3.9723119003523184 -5.62516538263036 -4.829570651115459 -1.2950948013109767 7.302412416568166 -3.043678812305364 -3.149850274277347 -6.476944546181209 -0.5807442791158823 -4.080078654055604 -3.1611933621382597 -0.11637063086775598 1.6049131611665592 5.044497534034215 0.3838925988521055 5.778293566481567 4.058620434329893 5.927479580737815 2.489198330275847 1.3107947997423626 1.5828295303331719 0.024839158566965516 -0.5476121359730696 0.87259267290178 0.9361180475548712 -1.5960762918622518 -5.611058251792273 -0.1594321010434905 -4.760816879788385 -0.07479939429503339 -1.7483043512234622 -2.8457787380793556 -1.7121754676101464 -3.787278050262899 3.7473965097918542 -1.659644247031472 -0.09111384850703107 2.4558095815874137 -0.06434581404575994 -3.7711115877495898 -0.2647997786903864 7.047915131872554 2.696723847584077 2.0890029827477234 -1.6825745638184928 -3.5887592066629557 -1.6594244317183802 -3.1951431164448874 3.27560938604933 2.334479543234365 2.9783519550285447 4.899933974871159 -2.2328606908007633 1.600105125583785 -2.1591853807024437 5.713548445622229 2.1891014794399264 -4.680943918675132 -2.5283217348396123 -2.6580555791689666
I don't understand, how can I fix this?
You need to transpose the matrix, you got it right. The vectors must be on the raws
Any ideas on how to fix this?
GMDISTRIBUTION implements the standard Expectation-Maximization (EM) algorithm. In some cases, it may converge to a solution which contains singular or close-singular covariance matrix for one or more components. Those components usually contains a few data points almost lying in a lower-dimensional subspace. A solution with singular covariance matrix is
usually considered as spurious. Sometimes, this problem may go away if you try another set of initial values; Sometimes, this problem will always occur because of any of the following reasons:
The number of dimension of data is relatively high, but there are not enough observations.
Some of the features(variables) of your data are highly correlated.
Some or all the features are discrete.
You try to fit the data to too many components.
In your case, it seems that the number of components that you used, 8, is too big. you can try to reduce the number of components. Generally, there are also other ways that you can use to avoid getting "Ill-conditioned covariance matrix" error message"
If you don't mind to get solutions with ill-conditioned covariance matrix, you can use option 'Regularize' in the GMDISTRIBUTION/FIT function to add a very small positive number to the diagonal of every covariance matrix.
You can specify the value of 'SharedCov' to be true to use equal covariance matrix for every component.
You can specify the value of 'CovType' to be 'diagonal' .
See also
http://www.mathworks.com/matlabcentral/newsreader/view_thread/168289
Should I be using only upto 12 cols at a time?
No
#Shark
I had the same problem, trying to generate an Gaussian MM object from a set of data.
I solved it by specifing the type of covariance:
GMM1=gmdistribution.fit(X,k,'CovType','diagonal')
GMM1 is the object name. You can find the meaning of X and k in
help gmdistribution.fit
If this doesn't work for you, try specifying the initial values of the EM algorithm
that gmdistribution already uses to generate the GMM.
Elios
first of you should make it linear because it is too big for matlab to do it, after that its better to just take 7-10 features (i think you get more than this).
after you did your work then use reshape function in order to make it what you want
I need to remove first 1024 bytes of a wave file. I tried to do but I got corrupted/distorted wavfile:
wavFile = fopen(fullFileName, 'r'); % Open file for reading
fseek (wavFile, 1024, -1);% Skip past header, which is 1024 bytes long.
wF = fread (wavFile, inf, 'int16');% 16-bit signed integers
wF = wF(:)';
newWavFile = fopen(strcat('new_',fileNames(fileNo).name), 'w+');% Open file for reading
fwrite(newWavFile,wF);
fclose(wavFile);
What can be the problem?
I could manage to remove header and correct the distortion by :
wavFile = fopen(fullFileName, 'r');% Open file for reading
fseek (wavFile, 1024, -1);% Skip past header, which is 1024 bytes long.
wF = fread (wavFile, inf, 'int16');% 16-bit signed integers
wF = wF(:)';
wF = 0.8*wF/max(abs(wF));
newWavFile =strcat('1_',fileNames(fileNo).name);% Open file for reading
wavwrite(wF,16000,16,newWavFile);