The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Extract Data from worksheet
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

tschunck

Germany
13 Posts

Posted - 06/28/2024 :  06:25:35 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): Origin 2024b (64-bit) 10.1.5.132
Operating System: Win11

I am trying to extract data that meets special conditions from a worksheet. I know that there exists a worksheet-extract-x-function calles "wxt" for this purpose bust since I want to do further calculations with the data I would prefer to have them in a range or dataset or something like this. I don´t want to open new windows and wait for the graphics to be build up because I have to repeat this operation several tmies in one script and don´t want to get it too slow.
After e.g. setting a filter condition to a col I want to have the first appearing entry as first element in dataset. Second shown etry should be second element of dataset ....
Can anybody help me?
Its like using wxt-function but output should be a dataset!

ChaoC

USA
185 Posts

Posted - 07/01/2024 :  10:43:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello tschunk,

You could copy your data filtered column to a stringarray and then convert it to a dataset. E.g. For data filtered col(A):

stringarray sa;
sa.CopyFrom(col(A));
int n=sa.GetSize();
create ds -t n;
sa.CopyTo(ds);


Best,
Chao
Go to Top of Page

tschunck

Germany
13 Posts

Posted - 07/02/2024 :  10:32:05 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi ChaoC,
thanks for your excellent tip. That seems to be exactly what I was looking for. I tried it out with the following example:
col(A) holds 6 elements (800,700,20,30,900,40) and col(B) gives a category (a,a,b,b,a,b).
Then I used the following skript:

wks.col2.filter = 1; // apply filter
wks.col2.filterx$ = "F2";
wks.col2.filter$ = "F2="b"";
wks.runfilter();

stringarray sa; // your suggestion
sa.CopyFrom(col(A));
int n=sa.GetSize();
create ds -t n;
sa.CopyTo(ds);

wks.col2.filter=0; //delete filter
wks.runfilter();

Everything fine so far and ds really hold the 3 elements in the right places.

But: Still one unexpected thing.
The hidden rows (because of previous filtering) remain unvisible.
How to force origin to show them again?


Just found it:

wks.col2.filter = 0;
wks.runfilter(2); //force update even there is no filter



Thanks again




Edited by - tschunck on 07/02/2024 10:59:38 AM
Go to Top of Page

tschunck

Germany
13 Posts

Posted - 07/03/2024 :  04:20:37 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Sorry for asking again.

I followed the proposed solution and at first everything seenms to work fine.
Actually, over the further course I had some difficulties.

I wanted to calculate the mean value of the values stored in ds for a predefined range and tried to use:

mean(ds[$(counter1):$(counter2)]);


this seems not to be possible. I don´t understand why I can´t use this dataset for further calculation. Is it because it originated from a string array and is not interpreted as array of numbers?

Thanks again
Peter
Go to Top of Page

ChaoC

USA
185 Posts

Posted - 07/03/2024 :  09:43:45 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello tschunk,

It is not because it originates from a stringarray.
You can confirm this by trying mean(ds);

My understanding is that mean() calculates entire named vector. So what you need to do is define a new vector with partial range.

range r1=[??]!ds[$(counter1):$(counter2)];
double aa=mean(r1);

Best,
Chao
Go to Top of Page

tschunck

Germany
13 Posts

Posted - 07/05/2024 :  10:30:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for answering again. That seems to work fine!

range r1=[??]!ds[$(counter1):$(counter2)];

Is that kind of notation - 3 questionmarks as workbookname - special for "hidden" ranges? Is it like declaring a dataset?

Go to Top of Page

tschunck

Germany
13 Posts

Posted - 07/08/2024 :  11:13:53 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I am now working in my skript since days and finally it turns out that the filters don´t work as they shoud.
Its hard to describe because the behaviour is completely incosistent.

I am using the filters inside of loops and try to change the content of the filters with each iteration.
Sometimes filters are apllied as programmed and sometimes not.

In order to debug my skript I entered type -b "Hello world"; commands in order to have breaks and see what exactly is going on. When I do this, I see that the contents of the filter are correctly set as I wanted it but Origin does sometimes apply filtering according to conditions, sometimes not. This seems to have somethimg to do with time. When I have a sufficient number of type -b commands and when I am waiting for each box to build up properly before I hit "Enter" everything is performed correctly.

It seems that there exists a timing problem that I can´t understand.


All that stuff is only necessary because I want to avoid the worsheet extract X-function which always leeds to a new output worksheet which has to be displayed and deleted if not used anymore. If there was any method to relyably extract data with preconditions and store that data into a loose range or dataset without talking the time consuming road of building up a new worksheet, displaying the data .... I would be fine.

Next I am trying to loop over all the rows in my workbook and extract my data manually, which is disappointing and presumably slower than everything else.


Go to Top of Page

ChaoC

USA
185 Posts

Posted - 07/09/2024 :  08:55:08 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:

range r1=[??]!ds[$(counter1):$(counter2)];

Is that kind of notation - 3 questionmarks as workbookname - special for "hidden" ranges? Is it like declaring a dataset?



See the documentation: https://www.originlab.com/doc/LabTalk/Tutorials/Tutorial-Range-Notation#Loose_Datasets

quote:

This seems to have somethimg to do with time. When I have a sufficient number of type -b commands and when I am waiting for each box to build up properly before I hit "Enter" everything is performed correctly.

It seems that there exists a timing problem that I can´t understand.




You can try adding pauses, sec -p, in your code to allow time for the filtering to finish executing.
https://www.originlab.com/doc/LabTalk/ref/Second-cmd#-p.3B_Pause_for_the_specified_number_of_seconds

Best,
Chao
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000