Why does paraview give an error even when the number of cells in the lattice and the number of data points match? - paraview

Why does paraview throw up the error "Number of cells do not match" when instructed to open a .vtk file? I have carefully checked the file for an inadvertent mismatch between the number of points and the number of cell_data points. There is no such mistake in the file. I know there is no way one can find the source of the error without looking at the code. However, it seems files cannot be uploaded here. As a workaround, I post here a short code written in the same format as the original code. This code also suffers from the same problem.
# vtk DataFile Version 2.0
avpol
ASCII
DATASET STRUCTURED_GRID
DIMENSIONS 2 2 2
POINTS 8 float
1.00000000000000000000 1.00000000000000000000 1.000000000000000
1.00000000000000000000 1.00000000000000000000 2.000000000000000
1.00000000000000000000 2.00000000000000000000 1.000000000000000
1.00000000000000000000 2.00000000000000000000 2.000000000000000
2.00000000000000000000 1.00000000000000000000 1.000000000000000
2.00000000000000000000 1.00000000000000000000 2.000000000000000
2.00000000000000000000 2.00000000000000000000 1.000000000000000
2.00000000000000000000 2.00000000000000000000 2.000000000000000
CELL_DATA 8
SCALARS avpol float 1
LOOKUP_TABLE default
6.1878484E-02
9.0861745E-02
0.1041844
0.1083797
0.1151097
0.1139994
0.1119415
0.1097126 `

Related

Symmetry of the output of fft2 command in matlab

When I run in matlab
fft2([9.36,-3.42,-2.12;-3.42 0.8 3.68 ;-0.6 -3.88 -4.96 ; 2.82 0.52 2.82])
I obtain
1.6000 + 0.0000i 11.4400 + 4.6765i 11.4400 - 4.6765i
13.2600 + 5.1000i 8.8123 + 8.8711i 7.8077 + 4.7489i
-12.8400 + 0.0000i 20.4600 - 4.2955i 20.4600 + 4.2955i
13.2600 - 5.1000i 7.8077 - 4.7489i 8.8123 - 8.8711i
What is the symmetry of this last matrix? I know that in the fft there exists some symmetry used to do not store all the information of the matrix, and I need to know what is the symmetry of the matrices output of the command fft2.
Some of context (I do not if is useful for the question/answer):
I need understand this because the output of the Fast Fourier Transform using fttw3 library I obtain the vector
1.6
13.26 + 5.1i
-12.84
11.44 + 4.6765i
8.8123 + 8.871i
20.46 - 4.2955i
11.44 - 4.6765i
7.8077 + 4.7488i
20.46 + 4.2955i
***
***
***
As you see, are almost all the elements of the initial matrix, but I do not have the last row, and I think that this values could be calculated using some symmetry.
Thanks in advance.

add tabs (spaces) to strings in plots for Octave / Matlab

How can I add tabs (spaces) to strings for plots in Octave see code below. It doesn't create a tab (There should be a tab between Signal and Max Freq in the plot)
Also it produces warning messages
warning: text_renderer: skipping missing glyph for character '9'
warning: called from
annotation>update_textbox at line 1080 column 11
annotation at line 248 column 7
clf
plot(0:0)
var=456
t1='Signal ';
t2=[char(9), 'Max Freq'];
t3=[char(10), 'nextline',num2str(var)];
str=strcat(t1,t2,t3);
annotation('textbox',...
[0.15 0.65 0.3 0.15],...
'String',{str},...
'FontSize',14,...
'FontName','Arial',...
'LineStyle','--',...
'EdgeColor',[1 1 0],...
'LineWidth',2,...
'BackgroundColor',[0.9 0.9 0.9],...
'Color',[0.84 0.16 0]);
Ps: I'm using Octave 4.2.2 on Ubuntu 18.04 64bit
I added t4 for blanks...doesn't look very nice. Also note I am using Matlab, not Octave so I didn't get your error. Not sure about that.
clf
plot(0:0)
var=456
t1='Signal ';
t4 = blanks(5);
t2=[char(9),t4, 'Max Freq'];
t3=[char(10), 'nextline',num2str(var)];
str=strcat(t1,t2,t3);
annotation('textbox',...
[0.15 0.65 0.3 0.15],...
'String',{str},...
'FontSize',14,...
'FontName','Arial',...
'LineStyle','--',...
'EdgeColor',[1 1 0],...
'LineWidth',2,...
'BackgroundColor',[0.9 0.9 0.9],...
'Color',[0.84 0.16 0]);

Decide best 'k' in k-means algorithm in weka

I am using k-means algorithm for clustering but I am not sure how to decide best optimal value of k based on the results.
For ex, i have applied k-means on a dataset for k=10:
kMeans
======
Number of iterations: 16
Within cluster sum of squared errors: 38.47923197081721
Missing values globally replaced with mean/mode
Cluster centroids:
Cluster#
Attribute Full Data 0 1 2 3 4 5 6 7 8 9
(214) (16) (9) (13) (23) (46) (12) (11) (40) (15) (29)
==============================================================================================================================================================================================================================================================
RI 1.5184 1.5181 1.5175 1.5189 1.5178 1.5172 1.519 1.5255 1.5175 1.5222 1.5171
Na 13.4079 12.9988 14.6467 12.8277 13.2148 13.1896 13.63 12.6318 13.0518 13.9107 14.4421
Mg 2.6845 3.4894 1.3056 0.7738 3.4261 3.4987 3.4917 0.2145 3.4958 3.8273 0.5383
Al 1.4449 1.1844 1.3667 2.0338 1.3552 1.4898 1.3308 1.1891 1.2617 0.716 2.1228
Si 72.6509 72.785 73.2067 72.3662 72.6526 72.6989 72.07 72.0709 72.9532 71.7467 72.9659
K 0.4971 0.4794 0 1.47 0.527 0.59 0.4108 0.2345 0.547 0.1007 0.3252
Ca 8.957 8.8069 9.3567 10.1238 8.5648 8.3041 8.87 13.1291 8.5035 9.5887 8.4914
Ba 0.175 0.015 0 0.1877 0.023 0.003 0.0667 0.2864 0 0 1.04
Fe 0.057 0.2238 0 0.0608 0.2013 0.0104 0.0167 0.1109 0.011 0.0313 0.0134
Type build wind non-float build wind float tableware containers build wind non-float build wind non-float build wind float build wind non-float build wind float build wind float headlamps
There are various methods for deciding the optimal value for "k" in k-means algorithm Thumb-Rule, elbow method, silhouette method etc. In my work I used to follow the result obtained form the elbow method and got succeed with my results, I had done all the analysis in the R-Language.
Here is the link of the description for those methods link
Try to find the sub links of the given link, build a code for any one of the method & apply on your data.
I hope this will help you, if not I am sorry.
All the Best with your work.

Why does using `solve` with a multivariate system of equations error unexpectedly?

While trying to solve a system of equations with 2 variables and 2 unknowns (Izhikevich nullclines), I encountered an unexpected error: Warning: 4 equations in 2 variables. and Warning: Explicit solution could not be found.
This is unexpected because as I stated, I was providing only 2 equations with the 2 variables, which should be a well-formed system of equations.
My relevant lines of code are as follows:
syms uu vv
[solvv, soluu] = solve([0.04*vv^2 + 5*vv + 140 - uu + I(t) == 0, a(t)*(b(t)*vv - uu) == 0], [vv, uu]);
The complete error trace is:
Warning: 4 equations in 2 variables.
\> In C:\Program Files\MATLAB\R2012b\toolbox\symbolic\symbolic\symengine.p>symengine at 54
In mupadengine.mupadengine>mupadengine.evalin at 97
In mupadengine.mupadengine>mupadengine.feval at 150
In solve at 160
In Q3_new at 37
In run at 64
Warning: Explicit solution could not be found.
\> In solve at 169
In Q3_new at 37
In run at 64
Confused, I went to MATLAB's documentation for solve and tried using the example snippet for solving a multivariate system of equations:
syms u v
[solv, solu] = solve([2*u^2 + v^2 == 0, u - v == 1], [v, u])
The expected output of this snippet, according to the documentation, is:
solv =
- (2^(1/2)*1i)/3 - 2/3
(2^(1/2)*1i)/3 - 2/3
solu =
1/3 - (2^(1/2)*1i)/3
(2^(1/2)*1i)/3 + 1/3
but the snippit instead returns:
Warning: 4 equations in 2 variables.
\> In C:\Program Files\MATLAB\R2012b\toolbox\symbolic\symbolic\symengine.p>symengine at 54
In mupadengine.mupadengine>mupadengine.evalin at 97
In mupadengine.mupadengine>mupadengine.feval at 150
In solve at 160
Warning: Explicit solution could not be found.
\> In solve at 169
solv =
[ empty sym ]
solu =
[]
as before.
Now I know I'm not making some beginner's mistake with my code because even the example code errors in the same way. Calling the singlevariate example snippit works as expected. I have tried this with MATLAB 2012a and MATLAB 2014a.
What could explain this unusual behaviour?
Can duplicate this on MATLAB 2014a. I found that if I already defined the variables using syms you can let solve resolve the variables automatically.
syms u v
[sv, su] = solve([2*u^2 + v^2 == 0, u - v == 1], [v, u]) % Doesn't work
% works but order-unspecified so this is not desirable
[su, sv] = solve([2*u^2 + v^2 == 0, u - v == 1])
Another user points out a mistake in using the incorrect documentation. MATLAB 2014a uses the following notation instead for re-ordered solutions. The other form seems to be for 2015. You should probably verify this holds true in 2012a but it seems to do so
syms u v
[sv, su] = solve([2*u^2 + v^2 == 0, u - v == 1], v, u)

Extract only numerical data from MATLAB from a text file into a matrix

I have a code which is producing output files containing information about some mesh which I need to analyse using MATLAB.
The output files look like this.
Vertex 1 1.3 -2.1 0 {z=(1.3e+0 -2.1e+0) mu=(1.4e-3 2.0e-3) uv=(-0.6 0.4)}
Vertex 2 1.4 -2.1 0 {z=(1.4e+0 -2.1e+0) mu=(2.8e-3 1.5e-3) uv=(-0.6 0.4)}
Vertex 3 -1.9 1.9 0 {z=(-1.9e+0 1.9e+0) mu=(-8.9e-2 1.4e-1) uv=( 0.7 -0.2)}
.
.
.
I would like my MATLAB code to read in this data file and form a matrix containing all the numbers
in the order specified.
So e.g I would want the above 3 lines to be processed into the matrix
1 1.3 -2.1 0 1.3e+0 -2.1e+0 1.4e-3 2.0e-3 -0.6 0.4
2 1.4 -2.1 0 1.4e+0 -2.1e+0 2.8e-3 1.5e-3 -0.6 0.4
3 -1.9 1.9 0 -1.9e+0 1.9e+0 -8.9e-2 1.4e-1 0.7 -0.2
Is there some convenient MATLAB facility/command to do this?
I think you could use textscan for this:
Example date.txt:
Vertex 1 1.3 -2.1 0 {z=(1.3e+0 -2.1e+0) mu=(1.4e-3 2.0e-3) uv=(-0.6 0.4)}
Vertex 2 1.4 -2.1 0 {z=(1.4e+0 -2.1e+0) mu=(2.8e-3 1.5e-3) uv=(-0.6 0.4)}
Vertex 3 -1.9 1.9 0 {z=(-1.9e+0 1.9e+0) mu=(-8.9e-2 1.4e-1) uv=( 0.7 -0.2)}
Code:
fileID = fopen('data.txt');
C = textscan(fileID,'Vertex %f %f %f %f {z=(%f %f) mu=(%f %f) uv=(%f %f)}');
fclose(fileID);
mtxC = [C{:}];
Result:
mtxC =
1.0000 1.3000 -2.1000 0 1.3000 -2.1000 0.0014 0.0020 -0.6000 0.4000
2.0000 1.4000 -2.1000 0 1.4000 -2.1000 0.0028 0.0015 -0.6000 0.4000
3.0000 -1.9000 1.9000 0 -1.9000 1.9000 -0.0890 0.1400 0.7000 -0.2000
MATLAB Option (partly tested)
I had to do something similar with a CMM once and it was easy to do in Python (see below). You could use the MATLAB command regexp(text, expression) to match a regular expression that gets what you want. This will return string data though, which you can save to a data file and then load that data file, or convert to numbers using str2double.
To use this, you first have to get your data file into MATLAB as series of strings. You can do this with fgetl.
in_fid = fopen('my_input_file.txt', 'r');
out_fid = fopen('my_output_file.txt', 'w');
data = [];
line = fgetl(in_fid);
while ischar(line)
match = regexp(line, '[+-]?\d+\.?\d*e?[+-]?\d*', 'match'); % find all matches
% Write to text file
fprintf(out_fid, '%s\t', match); % write values to file with tabs between
fprintf(out_fid, '\n'); % write a new line to the file
% Or save to an array locally
data = [data; str2double(match)];
line = fgetl(in_fid); % grab the next line
end
fclose('all');
% If you wrote to a text file, retrieve the data
data = dlmread('my_output_file.txt', 'delimiter', '\t'); % not sure about this...
Note that this will not match numbers that begin with a decimal point with no preceding digit, i.e. .2. Also note that this will match numbers that match the pattern in any file that you feed it, so it is generalized. For how to match floating point numbers, see this site (I changed it a bit though to add the e portion for scientific notation).
I was able to test the regexp and str2double operations on a remote machine, and it looks like building your data array directly works. I was unable to test the file I/O portion, so there may be some bugs there still.
Python Option (my favorite)
I suggest using regular expressions in Python for this sort of thing. I had to do something similar with a CMM once and it was easy to do in Python with something like:
import re
# Make pattern to match scientific notation numbers
pattern = re.compile(r"[+-]?\d+\.?\d*e?[+-]?\d*")
with open("your_input_file.txt", "r") as in_file:
with open("your_output_file.txt", "w") as out_file:
for line in in_file:
match = pattern.findall(line) # find all matches in the line
out_file.write("\t".join(match) + "\n") # write the results to a line in your output
For a good introduction to regex in Python, see Dive Into Python 3, which I recommend just about everybody reads. I tested this on your example file and it gives me:
1 1.3 -2.1 0 1.3e+0 -2.1e+0 1.4e-3 2.0e-3 -0.6 0.4
2 1.4 -2.1 0 1.4e+0 -2.1e+0 2.8e-3 1.5e-3 -0.6 0.4
3 -1.9 1.9 0 -1.9e+0 1.9e+0 -8.9e-2 1.4e-1 0.7 -0.2
in your_output_file.txt, so I think it works! The last step then is to just dlmread('your_output_file.txt', 'delimeter', '\t') in MATLAB and you should be good to go.
If you want to get fancy, you could upgrade your Python script so that it can be called from the command line with your input and output files as arguments (look into the sys.argv method), but this gets a bit more complicated and it is easy enough to just open the script and change the filename manually. Unless you need to do this all the time on differently-named files, in which case arguments are a good route. There is a good example of this here.