05-25-2020 03:09 AM
Hello.
I have been stuck with this for a couple of days now.
I have an array that I want to split into different sizes and store them.
The array I want to split Y = [1 2 3 4 5]
Then I have another boolean array (B) the same size as Y. This boolean array shall decide how to split Y.
B = [F T T F T]
My output that I am seeking would then be 2 arrays [2 3] and [5]
Since they are different sizes I think the best way would be to input the resulting arrays to a cluster containing an array?
But I have no more ideas on how to this. I have tried to used for loops with the splitting but end up with problems with index 0 and the storing of the results.
Is there anyone that have faced the same problem and could point me in the right direction?
Best regards
Peter
Solved! Go to Solution.
05-25-2020 03:17 AM
Hi CLD,
@CLDmannen wrote:
Since they are different sizes I think the best way would be to input the resulting arrays to a cluster containing an array?
Yes.
In a 2D array all rows/columns have the same size, but in a 1D array of cluster of 1D array the "inner" arrays can have different length…
@CLDmannen wrote:
The array I want to split Y = [1 2 3 4 5]
Then I have another boolean array (B) the same size as Y. This boolean array shall decide how to split Y.
B = [F T T F T]
My output that I am seeking would then be 2 arrays [2 3] and [5]
Algorithm:
Add some error handling on your own…
05-25-2020 04:37 AM
Thank you for your reply!
But I think you underestimated the problem alittle. (As did I)
This solution is semi-according what you wrote. As you can see I get issues with the 0 index and for the next ittereation I would need to remove all "F" in the array or the search function will find the END element before the start element. This gets really fast a messy solution.
I will try to make it work and post when successful
Best regards
Peter
05-25-2020 04:44 AM - edited 05-25-2020 04:45 AM
Hi Peter,
@CLDmannen wrote:
But I think you underestimated the problem alittle. (As did I)
This solution is semi-according what you wrote. As you can see I get issues with the 0 index and for the next ittereation I would need to remove all "F" in the array or the search function will find the END element before the start element. This gets really fast a messy solution.
I don't think so…
At Search1DArray there is one more input: the index where to start with the search. Add one more shift register to your loop and the search and split will become very easy…
Why does your WHILE loop stop immediatly after the first iteration? I thought you want to find more than one block of TRUE bits!?
05-25-2020 04:55 AM
Yes, that is true I want to find all I did not have the time to finsih that part.
Good point with the start index, I had missed that. Will try.
/Peter
05-25-2020 05:37 AM
Thank you!
This is the final solution
05-25-2020 07:41 AM
Hi Peter,
@CLDmannen wrote:
This is the final solution
You can simplify your VI: