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
 Forum for Origin C
 Using Categorical Data
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

woodpecker

Germany
5 Posts

Posted - 06/23/2015 :  03:14:05 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I have been having trouble using and understanding how to access properties of categorized data using OriginC script.

I have been helping write a function in which I can plot categorical data from different worksheets on the same graph. I can do this all by hand in the Origin interface (by categorizing the data and then using the categories tab from the column properties to make sure all columns use the same CategoricalMap and thus recognize the same categories). But I cannot seem to find the correct OriginC functions to write an algorithm that can do this for me.

Specifically, this is what I am trying to do:
I set all the desired columns to categorical using the .SetAsCategorical() function from the Column class. I then create a CategoricalMap object using .GetCategoricalMap() function (again from the column class) on the first column which will have all the categories I want in the CategoricalMap.
Then here lies the problem. I want to set the other columns to the same CategoricalMap since they often have missing categories in their column that I need them to recognize in order to plot the data on the same graph. However, there does not seem to be any .SetCategoricalMap(CategoricalMap x) function associated with Columns. Is there some way to set a CategoricalMap like this?
If not, I have also thought about adding the categories that may be missing to an "incomplete" CategoricalMap, however the CategoricalMap class does not seem to have any getters or setters for its components (the categories). It does seem to have a lienar search that can return the index of a category that the map contains, but I cannot return the name of the category itself, nor can I add a category to the map.

Are there functions in or outside of the Column or CategoricalMap classes that can help me give my columns all the same categories?

For reference, here are links to the resources I am using for the Column class (http://www.originlab.com/doc/OriginC/ref/Column-Class) and the CategoricalMap class (http://www.originlab.com/doc/OriginC/ref/CategoricalMap).

Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 2015 (64-bit) Sr2
Operating System: Windows 7 enterprise

Sincerely,
Matt

Edited by - woodpecker on 06/23/2015 03:45:14 AM

jasonzhao

China
262 Posts

Posted - 06/24/2015 :  05:29:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,

Please refer to the example below:

void MyCategoricalMap()
{ 
    Worksheet wks=Project.ActiveLayer();
    if (wks)
    { 
		vector<string> vstrKey={"aa", "cc", "bb", "dd"};  //design your own categories map
		for(int ii=0;ii<5;ii+=2){
		wks.Columns(ii).SetAsCategorical(CMT_NOMINAL); //set column into categorical with normal mode
                wks.Columns(ii).GetCategoricalMap().ReplaceMap(vstrKey);  //update the categorical map
		}       
    }
}

and the worksheet and graph after execute:



Best regards!
Jason
OriginLab Technical Service

Edited by - jasonzhao on 06/24/2015 05:32:00 AM
Go to Top of Page

woodpecker

Germany
5 Posts

Posted - 06/26/2015 :  05:28:44 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much.
This worked very well!

Matt
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