Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine cellfun and subs in Matlab

I have some values stored in a matrix, e.g.

Matrix = [1,4,6]

and a cell array, such as:

CellArray{1} = [0,0,1,0]
...
CellArray{4} = [0,0,0,0,0,0,0,1]
...
CellArray{6} = [0,0,1,1,1,0]

For each element of the Matrix in CellArray, i.e. CellArray{Matrix(1:end)}, I want to substitute the ones with zeros. So far, I've thought of:

[Output] = cellfun(@(x) subs(x,1,0),{CellArray{Matrix}},'UniformOutput',false)

though, the ouput is not as I wanted...

like image 221
Jonas Avatar asked Jan 28 '26 10:01

Jonas


1 Answers

Since the example suggests that CellArray only contains vectors with 0s and 1s (and the question does not specify the opposite), may I suggest

Output = cellfun(@(x)zeros(1, numel(x)), CellArray(Matrix), 'uniformoutput', 0)

which really just replaces the entry with a zero vector of appropriate length.

like image 140
zeeMonkeez Avatar answered Jan 31 '26 05:01

zeeMonkeez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!