Add zeros to matrices same as length of another matrix
Show older comments
I have to determine the beta weights of an fmri data subset. To do this I think I should perform a multiple regression of the bold signal of the voxels with the Design matrix (convolved with the hrf) - please correct me if I'm wrong in this.
The problem is the bold values are in a 360x3 matrix and the Design is 369x5. This is probably a very long way about it but to be able to regress, I separated each bold voxel into a separate vector and tried to pad the end with zeros which gives me an error everytime. How do I change this code to work for matrices? Or can I add zeros to the bold 360x3 matrix to make it 369x3 in one go?
bold1=[bold1, zeros(1,length(X(:,1))-length(bold1))];
2 Comments
Jos (10584)
on 15 Mar 2018
You will get better answers if you are more precise in describing the exact error. " which gives me an error everytime " is very vague ...
Becky CNS
on 15 Mar 2018
Accepted Answer
More Answers (2)
Jos (10584)
on 15 Mar 2018
To pad an matrix A with zeros to match a larger or same-sized array B, you can use this:
A = magic(3)
B = ones(3, 5)
newA = zeros(size(B))
newA(1:size(A,1), 1:size(A,2)) = A
If you are sure the new dimensions are larger, this will also work:
A2 = magic(4)
B = ones(5,7) % all dimensions larger than A
A2(size(B,1), size(B,2)) = 0
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!