cutting a matrix A into 3 pieces with respect to matrix B

here we have :
A=[1 2 3 14 15 16 7 8]
B=[1 2 3]
we know location of B is over 14 15 16 of matrix A.
we need to get 3 different matrix as below:
c=[1 2 3]
d=[14 15 16]
e=[7 8]
whar are the commands? many thanks in advance

13 comentarios

Is the location within A known, or is it necessary to search A to find [14, 15, 16] ?
Explain how you know that [1,2,3] is "over" [14,15,16]. And what does that even mean - "over"? And since c is identical to B does that mean c is also "over" A (whatever that means)? But since the values of B matches up with the values of A in indexes 1 through 3, I would think that A would be "over" the first 3 elements of A rather than over elements 4-6. Please clarify.
Mori
Mori el 17 de Jul. de 2015
A is a long section including geographical coordination in columns 2 and 3, B is a short section with geographical coordination as well which located more or less in the central part of the A. Now, we need divide A into 3 parts, right side, overlapping part and left side. the only thing the have in common is located in column 2 and 3 and we need to column 1. Hope is clear
Mori
Mori el 17 de Jul. de 2015
@walter: location within A is known
Mori
Mori el 17 de Jul. de 2015
Matrix A is blue dots, B is orange, and I need to divide A into 3 segment : right side, overlapping part and left side
This is not clear!
Clear as mud. Perhaps you can use strfind() or ismember() but that's just a wild guess.
arun
arun el 17 de Jul. de 2015
Editada: arun el 17 de Jul. de 2015
From your plot I guess, A and B are functions of x (some independent variable). You want to extract the range of values of A and B having common x values in one array and other pieces in other two array. Am I right?
Your plot shows two curves, supposedly for A and B. But it doesn't match up with your example, and I don't know how c, d, and e would show up there. Most confusing is that the curves are plots of (x,y) coordinates whereas you don't have (x,y) pairs for A and B. If we are to assume that the x coordinate is the index, and the y coordinate is the value of A or B, then B should be plotted over on the left since it has indexes only from 1 to 3.
And you didn't answer my question about if c gives the same result as B. Why the silence? Do you not need our help anymore? If so, that's fine, just say so.
Please read this and this and clarify your question so that people have at least a small chance of helping you.
Mori
Mori el 17 de Jul. de 2015
Editada: Mori el 17 de Jul. de 2015
Hey Image Analyst, thanks for your time reading and thinking about the question, the reason was I just slept!!!! I am still dealing with that problem. Ok, let me give you a piece of exact A and B matrix.
A=[
505765.510948 3172819.231222 4.608248
505567.154882 3172594.096597 4.726565
505368.798815 3172368.961972 4.354385
505170.442749 3172143.827346 3.619613
504972.086683 3171918.692721 2.760506
504773.730616 3171693.558095 1.971971
504575.374550 3171468.423470 1.429517
504377.018483 3171243.288844 1.027038
504178.662417 3171018.154219 0.625120]
B=[505170.442749 3172143.827346 1818.243090
504972.086683 3171918.692721 1817.765807
504773.730616 3171693.558095 1817.288523]
as you see x and y of B corresponds to raw 4,5 and 6 of matrix A. Now, I want matrix c equal first three raw with all columns d= raw 4,5,6 and e= last three raw of matrix A.
hope I am clear.
Mortaza commented earlier "YES, EXACTLY but sometimes, they don't have exact x value, just difference as 0.0002" in response to arun
Is it known that those entries in B are bit-for-bit copies of the entries in A? Such as if A was indexed to produce B? Because when two floating point values are computed by even very very slightly different code, the results will not necessarily be equal due to floating point round-off. If the entries are not bit-for-bit copies then you will need to compare with a tolerance rather than compare for equality.
Mori
Mori el 17 de Jul. de 2015
I can manage to get column 2 and 3 of A and B exactly equal, i.e. bit-for-bit copies. tried your answer but got error message. lets take into account that Columns 2 and 3 is equal in both matrix.

Iniciar sesión para comentar.

 Respuesta aceptada

[tf, idx] = ismember(B, A, 'rows');
minidx = min(idx);
maxidx = max(idx);
c = A(1:minidx-1,:);
d = A(minidx:maxidx,:);
e = A(maxidx+1:end, :);

2 comentarios

Mori
Mori el 17 de Jul. de 2015
got this error
Mori
Mori el 17 de Jul. de 2015
Editada: Mori el 17 de Jul. de 2015
just changed 'rows' to 'legacy' and it worked. Thank you
[tf, idx] = ismember(B, A, 'legacy');
minidx = min(idx);
maxidx = max(idx);
c = A(1:minidx-1,:);
d = A(minidx:maxidx,:);
e = A(maxidx+1:end, :);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with Industrial Communication Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 17 de Jul. de 2015

Editada:

el 17 de Jul. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by