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.
Related
This is a fairly simple thing I think, but I cannot seem to get the right output that Im looking for. I am using matrices to represent state space models in simulink, and I am trying to get my states output to the workspace,
it is a simple 4x1 vector, and I tried just using the regular "to workspace" block, but it seems it concats to either a 2d or 3d vector..
I want to have a tx4 matrix output that I can reference the first state and plot for all simulation time(t) like x(:,1), the second state x(:,2) etc...
You can set a save format in a To Workspace block. Default this is set to timeseries, but you can set it to Array.
Looking at the doc for the Array setting:
If the input signal is a scalar or a vector, each input sample is output as a row of the array. Suppose that the name of the output array is simout. Then, simout(1,:) corresponds to the first sample, simout(2,:) corresponds to the second sample, and so on.
You want the first dimension not to be time, but your state vector, so transposing simout should do the trick.
simout = simout.'; % or tranpose(simout);
I am writing some code, whereby I store a greyscale image, which is split into 'blocks' in a 4D array. I will be looping through all the 'blocks' in the 4D array and will perform calculations based on the contents of the blocks compared to one another. I want to only compare the 'blocks' that are near each other, and to do this I can just calculate the distance between the 'blocks' and don't loop through the ones that are too far away. To do this I need the index of each 'block' in the 4D matrix, ultimately creating my question.
My code goes like this:
for i=4dmatrix1
for j=4dmatrix2
% Do calculations here involving the index of i
% and j in their respective matrices.
end
end
I have i and j, but I want to find their index in 4dmatrix1 and 4d matrix2 respectively. 4dmatrix1 and 4dmatrix2 are greyscaled images that have been split into "blocks" of 20x20 pixels. Each matrix in 4dmatrix1 and 4dmatrix2 is a "block" in image 1 and image 2. The reason I have used this method for storing the data as it still represents the shape of the image, just split into 20x20 blocks. In my head this is understandable, but maybe for programming, this is inefficient and should be changed. If so, what would you recommend looking into?
Thank you!
You can loop over the indices of a matrix in any dimension, and then map that to the subscripts using ind2sub. Basically, the syntax would be
[id1,id2,id3,id4] = ind2sub(size(my4Dmatrix, i));
And something similar for j.
Not really your question, but something doesn't seem quite right with how you're looping. Also, you should include a minimum working example, including generating a couple of matrices and using correct syntax (you cannot start a variable name in MATLAB with a number).
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)?
I use the surf function in MATLAB in order to create a 3D map.
This map is created by 2 vectors and for each combination of their values I have a third one that creates the surface.
Is there a way to save for each iteration these sets of three values somehow?
What I want to achieve is to have a matrix which will be as a map for every possible combination of these values.
I've made some efforts with 3D matrices but I made it even more complex and I had many errors because of the dimensions.
I've got a really big matrix which I should "upscale" (i.e.: create another matrix where the elements of the first are grouped 40-by-40). For every 40-by-40 group I should evaluate a series of parameters (i.e.: frequencies, average and standard deviation).
I'm quite sure I can make such thing with a loop, but I was wondering if there was a more elegant vectorized method...
You might find blockproc useful. This command allows you to apply a function (e.g. #mean, #std etc.) to each distinct block in a 2D matrix.