how separate the first one (Xp) from (Xn).?

3 Ansichten (letzte 30 Tage)
abdullah qasim
abdullah qasim am 26 Feb. 2019
Beantwortet: abdullah qasim am 26 Feb. 2019
now when I compleat the first signal, But now I want to separate Xn from Xp in the following
rs=[Xn, Xp]
but the length of Xn and Xp is different, therefor we truck the length
XNsize = length(Xn);
rf =[XNsize, Xp, Xn];

Akzeptierte Antwort

John D'Errico
John D'Errico am 26 Feb. 2019
Bearbeitet: John D'Errico am 26 Feb. 2019
I have no idea why you are trying to do this using a vector. Far better would be to store your variables in a struct or a cell array. For example,
rs = {Xn,Xp};
Now you can recover Xn of Xp as simply rs{1} or rs{2}.
Or use
rs.Xn = Xn;
rs.Xp = Xp;
Here you extract Xn or Xp using rs.Xn or rs.Xp.
In either case, Xn and Xp are easily extracted. You need never pack the length of Xn into the vector, a kludge that serves no purpose, since in order to use those variables, you need to unpack them anyway.
Can you unpack the result from the vector? OF COURSE YOU CAN! But the point is, packing it all into a vector serves no purpose, especially since you have no idea how to unpack them in the first place. Yes, you are still out there, asking but if I really, really, really must do it the way I desperately wanted to do it, how would I have solved the problem using the kludge of packing it all into a vector?
Xn = rf(2:rf(1)+1);
Xp = rf(2 + rf(1):end);
Again, better would be just to learn to use MATLAB. Then you don't need to use a kludge solution in the first place.
  4 Kommentare
John D'Errico
John D'Errico am 26 Feb. 2019
Bearbeitet: John D'Errico am 26 Feb. 2019
No. Sorry. But there is not.
As you stated to claim to create rs...
x = 1:3;
y = 2:2:10;
rf = [length(x),x,y]
rf =
3 1 2 3 2 4 6 8 10
Now, recover the two vectors:
Xn = rf(2:rs(1)+1);
Xp = rf(2 + rs(1):end);
Xn
Xn =
1 2 3
Xp
Xp =
2 4 6 8 10
There is NOTHING lost.
Even so, if you use the method you seem to want to use, AND you try to reconstruct it as I show, AND you think that something was lost, then you either do not have what you explicitly stated you created, or you do not understand what the code does, and you never even tried it.
Regardless, this is a silly way to do things.
John D'Errico
John D'Errico am 26 Feb. 2019
And I have no idea what you are asking in your followup question, which seems totally unrelated to this question. If you have another question, then ask it separately. And if you want a useful answer, then be more clear about what you mean by the words "reshape" and "damage", as they have no meaning on their own. Only you know what they mean to you.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

abdullah qasim
abdullah qasim am 26 Feb. 2019
thank u very much
All the appreciation to you thank you very much

Community Treasure Hunt

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

Start Hunting!

Translated by