I'm attempting to use the fscanf() command to read a text file. The text file contains a table of years (in the first column) and across the row is the rainfall for each month in that year. Nothing is in scientific notation. The file is called "OctavilleRainfall.txt", containing following:
1988 9.2 5.4 5.6 1.2 2.2 0.1 0.0 0.0 0.1 0.0 0.4 2.3
1989 12.3 3.4 2.1 1.9 1.2 0.5 0.1 0.0 0.3 0.3 0.5 2.1
1990 10.2 6.7 3.3 1.3 1.1 0.2 0.2 0.0 0.1 0.2 0.3 1.9
1991 9.0 2.3 4.8 0.7 0.6 1.1 0.0 0.0 0.0 0.1 0.6 3.4
My current code reads as follows:
file = fopen('OctavilleRainfall.txt');
A = fscanf(file,'%f',[13 inf])
But when A displays, it is in scientific notation.
I'm not sure why it is in scientific notation, as I'm using the format command f not e. I need it not in scientific notation to be able to do my work. Any suggestions on how to fix this? It would be much appreciated.
The problem is not with fscanf(), but rather with the display format Matlab uses. Try changing it to a different format. Simply type:
format shortG
Note that the display format does not change any of the calculations performed, so it shouldn't affect your work.
Related
Currently I'm trying to take a list of values from my table and order them alphanumerically so they appear from number to letters. For example I have this data set:
3
8
0.64
0.64 + 2.8
70
90
AK
050LL (Beta)
070
PQ
W3
0.5
0.6
0.8
040
070
1.2
1.5
1.6
100
150
187
2.8
250
3.0
6.3
800
8mm
And I want it to print 0.5 first and then W3 last. I am using an Lpad to grab the data, but it displays like shown above, with no ordering. Is there a way I can sort these by numbers, then numbers+letters, finally letters in PostgreSQL? Do I need to have some special clause for the ordering to be correct?
The SQL statement:
SELECT *
FROM data_table
ORDER BY LPAD(parameter_type, 10) ASC
OFFSET 0 ROWS FETCH NEXT 1000 ROWS ONLY;
I'm trying to train a MLP to classify Iris dataset using ABC. From the code of ABC I get the optimal weights and biases I entered them to the code of testing it gave me 5 right classification and 10 wrong I think the fault in my code is in training process Which activation or transfer function is suitable to classify 3 type of data?
I get the output through this
trin= [4.7 3.2 1.6 0.2;
4.8 3.1 1.6 0.2;
5.4 3.4 1.5 0.4;
5.2 4.1 1.5 0.1;
5.5 4.2 1.4 0.2;
5.7 2.6 3.5 1;
5.5 2.4 3.8 1.1;
5.5 2.4 3.7 1;
5.8 2.7 3.9 1.2;
6 2.7 5.1 1.6;
6.7 3.3 5.7 2.1;
7.2 3.2 6 1.8;
6.2 2.8 4.8 1.8;
6.1 3 4.9 1.8;
6.4 2.8 5.6 2.1
];
trout=[-1;-1;-1;-1;-1;
0;0;0;0;0;
1;1;1;1;1];
inp=size(trin,2);
out=size(trout,2);
hidden=2;
x=[[1,1.970,-2,4,1,-3.450,5,-5,-2.650,3.300,4,-2,-1.920]];
iw = reshape(x(1:hidden*inp),hidden,inp);
b1 = reshape(x(hidden*inp+1:hidden*inp+hidden),hidden,1);
lw =
reshape(x(hidden*inp+hidden+1:hidden*inp+hidden+hidden*out),out,hidden);
b2=reshape(x
(hidden*inp+hidden+hidden*out+1:hidden*inp+hidden+hidden*out+out)
,out,1);
y = tanh(tanh(trin*iw'+repmat(b1',size(trin,1),1))*lw'+
repmat(b2',size(trin,1),1));
e = gsubtract(trout,y);
tind = vec2ind(trout);
yind = vec2ind(y);
percentErrors = sum(tind ~= yind)/numel(tind);
x vextor is the weights and biases witch I get from ABC optimization algorithm
You cannot really perform multi-class classification with a tanh output. For this a softmax activation is used, where the output is a vector of thre elements, corresponding to probabilities for each class.
I have a price series and I'd like to know the indices where there has been a change of x bips. I worked out a very ugly way to accomplish this in a loop e.g.
q)bips:200
q)level:0.001*bips / 0.2
q)price: 1.0 1.1 1.3 1.8 1.9 2.0 2.3
q)ix:0
q)lastix:0
q)result:enlist lastix
q)do[count price;if[abs(price[ix]-price[lastix])>level;result,:ix;lastix:ix];ix:ix+1];
q)result
0 2 3 6
This is a simple O(n) algo that walks through the price series and keeps a marked index (lastix) starts from the first element until it finds a price whose difference is greater than bips when found saves that index and updates lastix with the one found ... is there a more idiomatic way to do it?
My if condition inside the loop is somewhat flawed don't know exactly why if I check abs(price[lastix]-price[ix]) instead of abs(price[ix]-price[lastix]) it doesn't give correct results.
UPDATE: I was aware of deltasbut it compares consecutive elements only and that's not what I need in my OP. I apologize if the price series example in the OP was ambiguous and lead to correct results by simply using deltas. Here I have a counter example new prices series:
q)price: 1.0 1.1 1.21 1.42 1.4 1.32 1.63
q)where abs deltas price > level
,0
and this is not correct. The correct result which is produced by the accepted answer is still
0 2 3 6
I think you're looking for something like this maybe:
f:{where differ{$[level<abs[y-x];y;x]}\[x]}
this carries forward the last value that satisfied your condition and uses if for comparison with the scan adverb, and then uses differ to pick out where the condition was satisfied and values were updated.
If I've understood your problem correctly, the same result should come from
newprice:1 1.1 1.3 1.8 1.9 2 2.1
since the final value is more than 0.2 greater than 1.8, the last value at which the level was updated.
q)f newprice
0 2 3 6
Thanks,
Ryan
I'm not sure if this is exactly what you're looking for but deltas will give you the change between consectutive pairs:
q)deltas price
1 0.1 0.2 0.5 0.1 0.1 0.3
Checking for your condition returns a boolean list:
q)level<=deltas price
1011001b
Finally 'where' will return the indices:
q)where level<=deltas price
0 2 3 6
Thanks,
Jamie
level:0.001*bips:200;
result:where level<=abs deltas price:1.0 1.1 1.3 1.8 1.9 2.0 2.3;
result
0 2 3 6
Is this close to what you're looking for?
Deltas checks the difference between the current and next value, abs will take the absolute value, and then you're comparing each difference against "level", which you have predefine, using where to find the associated indice.
You've included index 0 in your answer but if you want to exclude it you can use the two argument form of deltas:
q)where level<=abs deltas[price 0;price]
2 3 6
Where the first argument sets the initial value to take away, in this case the first element of the price list.
An example of where this may be beneficial is if you were running the function for each date in a partitioned db you could pass in the last value from the previous day to ensure you didn't get the indices where there wasn't a significant difference of bips.
i use Ucinet to manipulate some data and i would plot it with NetDraw, but i have a problem
after normalization and affiliation i have a dataset as this:
A B C
A 0.0 0.5 0.5
B 0.5 0.0 0.5
C 0.5 0.5 0.0
In doing so, i do Visualize->NetDraw and, after that, File->Open->Ucinet dataset->Network, selecting the file above and the mode: "1-mode Network(s)". But when i try to do this i found the error "Access violation at address 0000000040C76E in module netdraw.exe. Write of address 0000000000000."
Can anyone help me?
Thank you
I solve this problem installing the 32-bit version of Ucinet. In doing so i solve all problem encountred before.
I'm trying to create a 10 x 8 array in MATLAB filled with floating-point values.
Ideas?
UPDATE:
I am actually trying to create an empty 10 x 8 float-type array. How can I do that?
You might want to have a look at the zeros function. To create a 10 x 8 matrix containing all zeros, use
matrix = zeros(10, 8);
To force the elements to be of a certain type (e.g. single precision), use the additional class argument like
matrix = zeros(10, 8, 'single');
(I think, the default is double precision)
matrix = single(rand(10,8));
float is a single in Matlab
rand(10,8); returns a matrix of dimension 10x8 formatted as doubles...you can cast the return value to single(rand(10,8)) to get floating point values...if for some reason you need to have floating point precision instead of double floating point procision
UPDATE: the clarification from the OP made this answer outdated.
If you just want to create a matrix with specific values, here is a one-liner approach:
data = [0. 0.1 0.2 3. 4. 5. 6. 7. 8. 0.9;0. 0.1 0.2 3. 4. 5. 6. 7. 8. 0.9; ...; 0. 0.1 0.2 3. 4. 5. 6. 7. 8. 0.9]
multi-liner approach (if you are about to copy-paste data):
data = [
0. 0.1 0.2 3. 4. 5. 6. 7. 8. 0.9
0. 0.1 0.2 3. 4. 5. 6. 7. 8. 0.9
0. 0.1 0.2 3. 4. 5. 6. 7. 8. 0.9
0. 0.1 0.2 3. 4. 5. 6. 7. 8. 0.9
...
0. 0.1 0.2 3. 4. 5. 6. 7. 8. 0.9
]
However, as many wrote rand(10,8) right off the bed, you can see, it is common practice not to use some kind of function to create a (10,8) matrix. Say: rand,ones, zeros, or some other tricks say reshape((1:1:80), 10, 8).
This is an old question but I'm posting my answer in case anyone stumbled across the same problem. Assuming that you're trying to get 32 digits precision, use
M=vpa(zeros(10,8)).