I'm trying to get a logical matrix as a result of the conditions that are specific to each column M(:,i)of the original matrix, based on the value of the same index iin the vector N, that is, N(i).
M(:,i)
i
N
N(i)
I looked it online, but I can not find anything like it. There should be a simple and clean way to do this.
M = 3 -1 100 8 200 2 300 4 -10 0 0 400 N = 4 0 90 7
and my sought-after solution for each column M(:,i)is less than N(i):
1 1 0 0 0 0 0 1 1 0 1 0
This is a standard use case for bsxfun:
bsxfun
O = bsxfun(@lt, M, N)
@lt "", .. <. bsxfun "" N , @lt M N.
@lt
<
M
, , for -loop:
for
O = zeros(size(M)); for row = 1:size(M,1) O(row,:) = M(row,:) < N; end
repmat:
repmat
O = M < repmat(N, size(M,1), 1);
MATLAB bsxfun .
arrayfun :
arrayfun
T = arrayfun(@(jj)M(:,jj) < N(jj), 1:numel(N), 'UniformOutput', false); result = cat(2,T{:});
: , bsxfun .
Source: https://habr.com/ru/post/1615366/More articles:Custom javascript countdown timer output style - javascriptScrolling middle click in VS code - visual-studioUsing two partial views in one view - htmlhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1615364/how-to-add-common-arguments-to-argparse-subcommands&usg=ALkJrhj7AEhqhcF72KDuq9qir7fInfeaRwИзменение размера изображения в открытом формате cv - pythonHow to make sure the certificate is not changed? - c #How to hide translator API key in android - javaКак обновить файлы *.ts(для Qt Linguist) в проекте CMake Qt? - qtMissing method in JavaScript API for Excel: copy sheet - excelOffice.EventType.DocumentSelectionChanged (in Excel) not working in all web browsers - office-jsAll Articles