I have some data in an HDF5 file, containing also stress and strain tensors for each cell type element. I created a XDMF file to describe the data, parts of it look like this:
<Attribute Name="Displacement" AttributeType="Vector" Center="Node">
<DataItem Dimensions="2673 3" Format="HDF" NumberType="Float" Precision="8" >
cubetest2.h5:/Solution/Nodal displacements
</DataItem>
</Attribute>
<Attribute Name="Force" AttributeType="Vector" Center="Node">
<DataItem Dimensions="2673 3" Format="HDF" NumberType="Float" Precision="8" >
cubetest2.h5:/Solution/Nodal forces
</DataItem>
</Attribute>
<Attribute Name="eleStrain" AttributeType="Tensor6" Center="Cell">
<DataItem Dimensions="2048 6" Format="HDF" NumberType="Float" Precision="8" >
cubetest2.h5:/Solution/Element strain
</DataItem>
</Attribute>
<Attribute Name="eleStress" AttributeType="Tensor6" Center="Cell">
<DataItem Dimensions="2048 6" Format="HDF" NumberType="Float" Precision="8" >
cubetest2.h5:/Solution/Element stress
</DataItem>
</Attribute>
while the vector values are just read fine, and I can create vector glyphs, the "Tensor Glyph" filter is always greyed out.
I suspect that ParaView creates a tensor with 9 components out of the six, but the documentation for Tensor Glyph states that it requires six values.
How is it possible to show the tensors, i.e. tell Paraview not to create a full symmetric tensor?
Tensor Glyph Filter does not support Cell Data operation.
You should first convert your Dell Data to Point Data using Cell Data To Point Data Filter.
Related
I have a hdf5 file where I have a big dataset containing a Nx3 matrix, to store positions in 3D. This dataset is referenced in several groups using softlinks, as shown in the hierarchy below
/
/POINTS (the big dataset)
/mesh0
/mesh0/POINTS (softlink to /POINTS)
/mesh1
/mesh1/POINTS (softlink to /POINTS)
However, to load this using h5py, I iterate on my groups and if I found a mesh (a group with an attribute called mesh), I assume there is a POINTS dataset and parse it. The issue is that this is creating new numpy matrices for each POINTS dataset.
# This creates a new numpy array, which is inefficient is we are dealing with softlinks
points = mesh_group["POINTS"][::]
I would like to know how to check if the link to the dataset is a softlink, so I can create the matrix only once.
I am receiving a text file with 1000 matrices of size 2x2 each day from someone, in the following format (only 3 matrices are shown here instead of 1000):
0.96875000 0.03125000
0.03125000 0.96875000
0.96875000 0.01562500
0.03125000 0.98437500
0.99218800 0.03125000
0.00781250 0.96875000
I need to make a 2x2x1000 array in MATLAB. Ideally I could do something simple like:
[0.96875000 0.03125000
0.03125000 0.96875000;
0.96875000 0.01562500
0.03125000 0.98437500;
0.99218800 0.03125000
0.00781250 0.96875000]
After reading the MATLAB documentation on multidimensional arrays and the MATLAB documentation for the cat function, I figured out that I could make the required array in the following way (the first argument of cat is 3 because I'm concatenating the 2x2 matrices along the 3rd dimension):
cat(3,...
[0.96875000 0.03125000
0.03125000 0.96875000],...
[0.96875000 0.01562500
0.03125000 0.98437500],...
[0.99218800 0.03125000
0.00781250 0.96875000])
But that does not work if I put spacing between the lines as in my "ideal" example above, and the need for all the commas and dots makes it a bit uglier in my opinion.
While writing this question, I have discovered that I can run my "ideal" example and then use reshape, which I prefer over my solution using the cat function. For this, I don't even need the semi-colons. However Cris Luengo correctly pointed out in the comments that reshape is not enough and permute is also needed, and then Luis Mendo pointed out in chat that the solution is not so simple:
permute(reshape(ideal.',2,2,[]),[2 1 3])
Andras Deak has done what we thought was impossible, which is to remove the transpose, but the solution is still quite complicated, and was not easy to engineer:
permute(reshape(ideal,2,[],2),[1 3 2])
Ideally one would not need to use cat or reshape to make a 3D array, when the original data is already so nicely formatted in what the human eye can already see is a 3D array of several 2x2 matrices.
Is there a simpler way to build the 3D array in MATLAB using the data in the format I have?
So far I have done the following on my own:
Searched online and found the above two MATLAB documentation articles which lead me to the above solution using cat
Came up with the above solution using reshape while writing this question, then it got improved by Cris and Luis in the comments and chat 😊.
Also: I tried saving the data in a .txt file and clicked import in MATLAB, knowing that the import GUI gives some options for how the data is to be organized in the resulting MATLAB array, but there did not seem to be any option to make this a 3D array.
Indeed there is no "direct" way to import this text as a 3D matrix. This is the easiest way I can come up with:
Save the input as a .txt file
Use the import tool (Import Data button in the Variable toolbar) to import the data as a Mx2 matrix. Choose "Numeric Matrix" as "Output Type". And you can "exclude rows with" "blank cells" to avoid the empty rows.
Besides reshape() and permute(), using cell array to format it as below might be more intuitive and less error prone to someones.
% The number of 2x2 matrices
N = size(m,1)/2;
% Split each 2x2 matrix into a cell
c = mat2cell(m, 2*ones(1,N), 1);
% Concatenate along the 3rd dimension
output3DMatrix = cat(3, c{:});
I want to feed caffe vectors of labels (multi label regression problem), so I have used the following link for creating hdf5 files.
Using this code, I created an image_list.txt which contains path of files and float labels in each line, e.g.
/home/deep/00000.bmp 0.9997 0.0236 -0.0082 -0.0231 0.9980 0.0588 0.0096 -0.0586 0.9982 -0.0046 0.1084 0.3938
but it seems that it only works for integer label.
when I run demo.m the following error comes:
Error using dataread
Trouble reading integer from file (row 1, field 3) ==> .9997 0.0236 -0.0082 -0.0231 0.9980
0.0588 0.
If you also use caffe's C++ interface, I would like to share you with this Multitask DataLayer and it supports float typed label vector for regression tasks. Here provides a simple example for learning facial expressions' label distribution which is a vector size of 8.
There are several example data sets in Matlab, for example wind and mri. If you execute the command load wind you will load the data in the data set wind. Some are included in toolboxes and some appear to be included in standard Matlab. These example data sets are valuable as test data when developing algorithms.
Where can one find a list of all such data sets included in Matlab?
You can enter demo in matlab to get a list. The wind table is part of Example — Stream Line Plots of Vector Data, etc.
For the tables on your computer, have a look at:
C:\Program Files\MATLAB\R2007b\toolbox\matlab\demos
The example data is located in .mat files in ../toolbox/matlab/demos.
The following data is available in MATLAB 2014a:
% in matlab run:
> H=what('demos')
> display(H.mat)
You can also use your favorite Linux console:
/usr/local/MATLAB/R2014a/toolbox/matlab/demos$ ls *.mat -1 | sed -e "s/.mat//g"
This is my list for readers who can not try it on their machine while reading this answer:
accidents
airfoil
cape
census
clown
detail
dmbanner
durer
earth
flujet
gatlin
gatlin2
integersignal
logo
mandrill
membrane
mri
patients
penny
quake
seamount
spine
stocks
tetmesh
topo
topography
trimesh2d
trimesh3d
truss
usapolygon
usborder
vibesdat
west0479
wind
xpmndrll
While the command demo in MATLAB 2018b will start a help browser with some demos:
You can find a list of all available dataset and their description in the following link :
https://www.mathworks.com/help/stats/sample-data-sets.html
I have generated a clustergram based on a dataset of normalized values, but I want to attempt to reorder the samples along the y-axis. I haven't come across much information on how to go about doing that after googling. Below is my code thus far: Any help would be appreciated.
[num, txt]= xlsread('S:\Breast\Breast Stats no post XRT.xls', 'Breast heat');
PID= txt(2:93,1);
varname = txt(1,2:23);
cgram = clustergram(num(1:92,:));
set(cgram,'Standardize',3,'Cluster',3, 'RowLabels',PID(:,:), 'ColumnLabels', varname(:,:),...
'Linkage','ward','Dendrogram',3,'ColumnPdist', 'euclidean', 'RowPdist', 'euclidean', 'OptimalLeafOrder', 'true',...
'SymmetricRange', 'false');
Also, does anyone know how to set the font size for the labels for ONE particular axis only?
About the main problem:
Suppose you put your data in nx2 a matrix A then you can sort it according to a column like this:
[Y,I]=sort(A(:,2)); % Sort by column 2 of the matrix
B=A(I,:); %use the indices from sort() to sort all rows of A.
To reorder the elements in the clustergram, you can set the OptimalLeafOrder property of the clustergram.
To set the font size for the labels, you can use the addXLabel or addYLabel commands, and then directly set the FontSize property of the text object returned.
See doc clustergram and doc addXLabel for more information and examples.