I'm trying to visualize some 4-D data using matlab's slice tool. But because the array is 4x4x4, i would like to visualize it by slicing at all levels.
I use the following code to generate a plot:
data=round(rand(4,4,4));
h=slice(data,1:4,1:4,1:4);
set(h,'FaceAlpha',0.3,'EdgeAlpha',1)
colormap gray
But the plot ends up representing a 3x3x3 array.
So it looks like matlab is interpolating some values. I've searched around to no avail -- how can i visualize the 4D data without interpolation (i.e., so each value in the array is represented by a cell in the figure)?
Related
I have a series of 3D arrays of dimensions 3x3x3 in Matlab. Matlab's ttest function returned 2D arrays and when I checked out the documentation I see that the method performs t-tests on columns. I want to perform a t-test that goes over the entire matrix space. How can I code this without manually creating my own t-test script?
Edit: I am hoping to get two outputs that contain the p-values and t-values output by the ttest method like in
[~,pval,~,tval] = ttest(x,y)
but thise only gives the 2D arrays mentioned above. I require the output be a 3x3x3 array giving the t-value at each point, and ideally another that contains the p-value corresponding to those t-values.
I'm trying to interpolate a 3D vector field. For every (x,y,z) position we have a vector (u,v,w). I have another set of points let's call them (xq,yq,zq) in which I don't have vector information (uq,vq,wq). I would like to interpolate my data to find the vectors at the points (xq,yq,zq).
I've tried to interpolate using several functions like griddata, by interpolating each vector component individually.
uq = griddata(x,y,z,u,xq,yq,zq);
vq = griddata(x,y,z,v,xq,yq,zq);
wq = griddata(x,y,z,w,xq,yq,zq);
I expect to obtain the vectors at the locations I specified, but the message I get is:
"Warning: The underlying triangulation is empty - the points may be
coplanar or collinear."
Is there a better way to interpolate a vector field?
I have used TSNE in MATLAB for dimensionality reduction of a large data. I have been able to generate the Scatter Plot for TSNE in 2 dimensions which shows the labels of the cluster in different colors for each label, but, I am unable to do so in 3D. Referring to https://uk.mathworks.com/help/stats/tsne.html, I used the following syntax:-
Where, merged_data_all is a 21392x1974 table with the last column named FunctionalGroup containing different labels (similar to the Fisheriris species labels in the Mathworks example on tsne). Y2 is the 3 dimensional variable which I have been successfully able to generate of dimensions 21392 x 3 double.
figure
v = double(categorical(merged_data_all.FunctionalGroup));
c = full(sparse(1:numel(v),v,ones(size(v)),numel(v),3));
scatter3(Y2(:,1),Y2(:,2),Y2(:,3),15,c,'filled')
title('3-D Embedding')
view(-50,8)
When I use this code, I get the error "Error using sparse- Index exceeds array bounds". I even tried to use a modified version of the code and doing something like this
scatter3(Y(:,1), Y(:,2),Y(:,3),merged_data_all.FunctionalGroup)
In case of this, I get the error "Error using scatter3- Input arguments must be numeric, datetime or categorical". I am quite confused as to how I can plot a 3d scatter plot, with 14 different colors (for the 14 types of different labels I have in my FunctionalGroup column of merged_data_all). Any help in this regard would be highly appreciated. Thanks
I use contourf function for plotting a 2D filled contour.
I get warning that some of the data points for Z are repeated and average values will be used in that case.
Can I somehow force Matlab to use the median values instead?
Thank you.
File: MyData.csv
I have a number of float arrays, and my purpose is to create a histogram for them. I want to get a graph of the values' frequencies - one graph per each array. and I need all the graphs to be shown on the same window, like this Opencv example does for rgb color histogram. I'm looking for a way to do it using OpenCv or to dump the values out to a file and do the histogram using Matlab. Any idea?
Matlab has a built-in histogram function - hist. It can calculate the histogram, or plot it, or both. For example, if f is a list of files with data you can use
for i=1:length(f)
d=importdata(f(i));
subfigure(length(f),1,i);
hist(d);
end
(Of course, you have to tweak the data importing thingy to make it work. I don't know what the format of your data is in)