Azzera filtri
Azzera filtri

function to calculate summation in matrix

2 visualizzazioni (ultimi 30 giorni)
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 Commenti
Azzi Abdelmalek
Azzi Abdelmalek il 31 Mar 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.

Accedi per commentare.

Risposte (1)

Roger Stafford
Roger Stafford il 1 Apr 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

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by