Borrar filtros
Borrar filtros

Creating a matrix with random numbers according to a condition

3 visualizaciones (últimos 30 días)
Rengin
Rengin el 8 de Oct. de 2013
Respondida: Image Analyst el 8 de Oct. de 2013
I want to create let’s say nx1 sized 'Result' matrix and I am putting the results of A1-B1,A2-B2,…An-Bn in each cell according to some tolerances (n=10). I mean according to An-Bn<=delta… The thing what I did that, I initialized zeros(n,1) for that Result matrix then I used if command for my tolerance condition. If it is satisfied, satisfying result is inserted in the cell or 0 stays in the cell, if the condition is not satisfied! As a result, I can fulfill let’s say 2 cell out of 10 and rest of it is zero (normally!). I want to keep searching until all my cells are fulfilled. Could you help me about that matter please?

Respuestas (1)

Image Analyst
Image Analyst el 8 de Oct. de 2013
result = A-B; % No initialization with zeros needed.
condition = whatever...some logical expressions such as result > 4.
% Zero out those elements not meeting the condition
result(~condition) = 0;

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by