I can not return real values

3 ビュー (過去 30 日間)
huda nawaf
huda nawaf 2012 年 9 月 14 日
Hi I have the result of recursive function is saved in txt file , Below are the results of calling recursive fun. that each call divide the vector into two vectors. the problem is when the function divide the vector , give the new vectors the indices of values in original vectors not the same values.So, I lose the real numbers
for ex. this txtfile
*3 4 5 8 9 10
1 2 3
4 5 6
3
1 2
1 2
3 *
I want code by which can return these vectors
*cluster(1)=[3 4 5 8 9 10]
cluster(2)=[3 4 5]
cluster(3)=[8 9 10]
cluster(4)=[5]
cluster(5)=[3 4]
cluster(6)=[8 9]
cluster(7)=[10]*
thanks in advance
  2 件のコメント
Image Analyst
Image Analyst 2012 年 9 月 14 日
Which one of the sets of values are "the results of calling recursive fun"??? All I see are the input, and the desired output, not the results of your recursive function.
huda nawaf
huda nawaf 2012 年 9 月 14 日
the first set the returned values(the indices of values) of recursive function, and the second set it is what i need.
the first vector in first set (txtfile)is the input, and the remaining values are the returend indices for the vector after dividing it each call.I saved the input in txtfile too.
thanks

サインインしてコメントする。

回答 (2 件)

Jürgen
Jürgen 2012 年 9 月 14 日
I am not sure if I get it , is not so clearly explained but I would work with the length of the OriginalVector of size(OriginalVector,2) and divide it by two ( you will need to use ceil or fix if you have an odd length of course
so in pseudo code
Length= length(V)
HalfLenght=ceil(Length/2)
V1=V(1:HalfLength) V1=V(HalfLength+1:Length)
repeat this until length result is one
or am I mistaken ?
  5 件のコメント
huda nawaf
huda nawaf 2012 年 9 月 14 日
the function divide the vector [3 4 5 8 9 10]at first into two vectors
[3 4 5] and [8 9 10] but it is returning indices of these values[1 2 3] and [4 5 6]
then divide the vector [3 4 5] into two vectors [5] and [3 4], but returns [3] and [1 2]; then divide the vector[ 8 9 10] into two vectors [8 9] and [10],but it returns [1 2] and [3].
these returning indices was stored in txtfile. I need code map these indices into the real values in original vector.
i.e need code map indices into
3 4 5
8 9 10
5
3 4
8 9
10
thanks
Jürgen
Jürgen 2012 年 9 月 15 日
Maybe it is because it is the weekend that I am slow but to be sure I'll try to check if I understand it: in your txt file you have a list of numbers that you read into matlab en put in a vector:x=[3 4 5 8 9 10]; then you divide the vector in parts being: [3 4 5] & [8 9 10]&[5]&[3 4]&[8 9]&10
what do you want to do next? write to the txt?

サインインしてコメントする。


Jürgen
Jürgen 2012 年 9 月 15 日
編集済み: Jürgen 2012 年 9 月 15 日
I think this code does what you want or no what I think that you want :-) Of course much nicer if you make a function of it X=[3 4 5 8 9 10];
L=length(X);
NewL=ceil(L/2);
Xnew1=X(1:NewL);
Xnew2=X(NewL+1:L);
X=Xnew1;
L=length(X);
NewL=ceil(L/2);
Xnew1=X(1:NewL);
Xnew1=X(NewL+1:L);
X=Xnew2;
L=length(X);
NewL=ceil(L/2);
Xnew1=X(1:NewL);
Xnew1=X(NewL+1:L);
  7 件のコメント
huda nawaf
huda nawaf 2012 年 9 月 16 日
I forget tell u the output u will see it in txtfile called group_1.txt
thanks
huda nawaf
huda nawaf 2012 年 9 月 19 日
hi , many thanks, I have solved the another problem.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by