필터 지우기
필터 지우기

Assign vector to vector with gaps

조회 수: 5 (최근 30일)
baxbear
baxbear 2016년 7월 16일
댓글: baxbear 2016년 7월 22일
Stuff doesn't matter - was tired - start reading at Edit1 - sry
Hello,
I have a matrix of row size m and a matrix of row size n where m > n and x = m - n. I also got a vector k of length x with different row indices of m. Now I want to assign n to m by not touching entries m(k) important is that these rows stay unchanged and in place.
Is there an easy one-liner? like:
m(m ~= x) = n;
or
m(m ~= m(x)) = n;
but seems not to work :(
Hope you can help me.
Thanks in advance.
=================================================================
HERE!:-> @Edit1: Oh, uff was late yesterday and yeah what ever I wrote there is pretty confusing and wrong... so again:
Matrix A of size m * _ where m is the number of rows and matrix B of size n * _ where n is the number of rows. Still true is: m > n and x = m - n and V is a vector with x rows.
Example:
A = [1,1,1; 2,2,1; 3,3,4; 8,3,6; 8,3,0; 8,6,3];
B = [4,2,5; 4,3,2; 6,3,2; 8,0,9];
V = [2; 4];
Result in A:
A = [4,2,5; 2,2,1; 4,3,2; 8,3,6; 6,3,2; 8,0,9];
just for much bigger matrices. Sorry for my unclear post yesterday hope you are still willing to help me.
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2016년 7월 16일
You can make your question clear by posting an example
Image Analyst
Image Analyst 2016년 7월 16일
편집: Image Analyst 2016년 7월 16일
Your terminology is pretty sloppy. Are m and n the width of the matrix (number of columns which is the "row size" or "row length") or the names of the matrices? Are your matrices really column vectors? Or row vectors?
This is what I have so far but can't go further because of ambiguities in your terminology.
m=10
n=6
x = m-n
vec1 = randi(99, 1, m) % First "matrix" (sample data)
vec2 = randi(99, 1, n) % Second "matrix" (sample data)
k = randperm(m, x) % indexes of m

댓글을 달려면 로그인하십시오.

채택된 답변

goerk
goerk 2016년 7월 19일
A = [1,1,1; 2,2,1; 3,3,4; 8,3,6; 8,3,0; 8,6,3];
B = [4,2,5; 4,3,2; 6,3,2; 8,0,9];
V = [2; 4];
% create 'inversion' of V (there may be better ways)
notV = 1:size(A,1); % vector from 1 to number of rows
notV(V) = []; % delete rows which are in V
% over write the rows that are not in V
A(notV,:)=B
  댓글 수: 3
goerk
goerk 2016년 7월 19일
Thanks, that's a nice short solution.
baxbear
baxbear 2016년 7월 22일
Thank you very much :D

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by