Borrar filtros
Borrar filtros

function to calculate summation in matrix

2 visualizaciones (últimos 30 días)
Firas Al-Kharabsheh
Firas Al-Kharabsheh el 31 de Mzo. de 2016
Comentada: Firas Al-Kharabsheh el 1 de Abr. de 2016
if i have a (M x N) matrix_A with zeros and another (M x N/2) matrix_B filled by number and combine these matrices to each other which the number in the matrix_B represent numbers of 1 in the matrix_A .. For Example
matrix_A = [0 0 0 0 0 0 0 0 0 0 ] ...... 10 of zeros
matrix_B = [1 2 2 2]
the solution must be in a first matrix after apply the function .. for the previous example the solution is
matrix_A = [1 0 1 1 0 1 1 0 1 1]
Note : in matrix_B between each of number of one's there must be a zero or more .
the equation is if N == ∑k(i) + (n-1) then the function will be apply . where ∑k(i) = 1+2+2+2 = 7 , (n-1) is the number of numbers in the row in matrix_B (4 -1) = 3 .. then when we apply the equation .. 10 == 7+3 ------ true then apply the function.
  2 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 31 de Mzo. de 2016
What is your question? to make it clear, post a short example, you don't need to post tens of numbers, just a small matrix, with expected result, explaining how to obtain it, sometimes, the expected result is enough to explain what you want.

Iniciar sesión para comentar.

Respuestas (1)

Roger Stafford
Roger Stafford el 1 de Abr. de 2016
Instead of inserting ones into a pre-existing A of zeros, it is easier to generate A from scratch:
A = [];
for k = 1:size(B,2)
A = [A,ones(1,B(k)),0];
end
A = A(1:end-1); % Remove the extra zero

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by