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
 Matrixsheet setting a fixed value to row/column
 New Topic  Reply to Topic
 Printer Friendly
Author  Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

AKazak

Russia
1235 Posts

Posted - 11/23/2025 :  02:27:15 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
OriginPro 2026 (64-bit) Beta6 10.3.0.156
Windows 10.0.19045.6575 Pro 22H2

Greetings!

I have a matrix book Mbook with a single matrix sheet MSheet with a single matrix object Mat(1).

Can you share a LT snippet to set a user-defined fixed value to the selected (specified by index) row/column of Mat(1), please?

I appreciate getting your response shortly.

---
Andrey

AKazak

Russia
1235 Posts

Posted - 11/23/2025 :  02:30:00 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I could not find the answer from the following resources:
https://www.originlab.com/doc/LabTalk/ref/Wks-Col-obj
https://www.originlab.com/doc/LabTalk/guide/Matrix-Basic-Operation
https://www.originlab.com/doc/en/X-Function/ref/msetvalue
https://www.originlab.com/doc/en/LabTalk/ref/Matrix-cmd
https://www.originlab.com/doc/LabTalk/guide/Matrix-Object-Data-Manipulation
https://www.originlab.com/doc/en/LabTalk/guide/Worksheet-Column-Data-Manipulation

---
Andrey

Edited by - AKazak on 11/23/2025 02:37:28 AM
Go to Top of Page

aplotnikov

Germany
173 Posts

Posted - 11/24/2025 :  03:35:29 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
https://www.originlab.com/pdfs/5_matrix.pdf

Note 2: You can reference a single cell

MatrixName[N*(i-1)+j]
where:
N = the number of columns in the matrix
i = the row number in the matrix.
j = the column number in the matrix.
Go to Top of Page

AKazak

Russia
1235 Posts

Posted - 11/24/2025 :  09:09:50 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by aplotnikov

https://www.originlab.com/pdfs/5_matrix.pdf

Note 2: You can reference a single cell

MatrixName[N*(i-1)+j]
where:
N = the number of columns in the matrix
i = the row number in the matrix.
j = the column number in the matrix.



Thank you for sharing this.
I will test this approach soon.

---
Andrey
Go to Top of Page

AKazak

Russia
1235 Posts

Posted - 11/24/2025 :  09:20:07 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by aplotnikov

https://www.originlab.com/pdfs/5_matrix.pdf

Note 2: You can reference a single cell

MatrixName[N*(i-1)+j]
where:
N = the number of columns in the matrix
i = the row number in the matrix.
j = the column number in the matrix.



https://www.originlab.com/pdfs/5_matrix.pdf does not mention matrix object and implicitly assumes a matrix with a single matrix object in it.

What is the general way to access/modify values in a certain matrix object?

---
Andrey
Go to Top of Page

aplotnikov

Germany
173 Posts

Posted - 11/24/2025 :  8:09:12 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by AKazak
https://www.originlab.com/pdfs/5_matrix.pdf does not mention matrix object and implicitly assumes a matrix with a single matrix object in it.

It is not true. You can use Mat(n)-notation to access n-th matrix object:
[<Matrix name>]<MSheet>!Mat(<n>)[N*(i-1) + j] = ...

For instance:
[MBook1]1!Mat(2)[66]=66

Go to Top of Page

minimax

365 Posts

Posted - 11/25/2025 :  05:25:32 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Andrey,

following script with cell() function should also work.

And it is recommended to define range to access.


range rmat1=[Mbook1]Msheet2!2;
rmat1!cell(2,3)=4;

Go to Top of Page

AKazak

Russia
1235 Posts

Posted - 11/25/2025 :  08:47:01 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by aplotnikov

quote:
Originally posted by AKazak
https://www.originlab.com/pdfs/5_matrix.pdf does not mention matrix object and implicitly assumes a matrix with a single matrix object in it.

It is not true. You can use Mat(n)-notation to access n-th matrix object:
[<Matrix name>]<MSheet>!Mat(<n>)[N*(i-1) + j] = ...

For instance:
[MBook1]1!Mat(2)[66]=66



Well noted.
Thank you!

---
Andrey
Go to Top of Page

AKazak

Russia
1235 Posts

Posted - 11/25/2025 :  08:58:06 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by minimax

Hi Andrey,

following script with cell() function should also work.

And it is recommended to define range to access.


range rmat1=[Mbook1]Msheet2!2;
rmat1!cell(2,3)=4;





Got it.
How do I refer to individual rows and columns of a matrix object?

---
Andrey
Go to Top of Page

minimax

365 Posts

Posted - 11/26/2025 :  04:32:24 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Andrey,

I am afraid currently there is no LT access on whole row/col (subset) of matrix.

You may take a look at Origin C interface, like
https://www.originlab.com/doc/OriginC/ref/matrixbase-GetAsVector
https://www.originlab.com/doc/OriginC/ref/matrixbase-SetByVector

Or if you are open to Python, you may take some try too, like below.


import originpro as op
import numpy as np
mb=op.find_book('m')
ms=mb[0]   #assume it is a 5*5 dimension obj
arr = ms.to_np2d(0)
row1 = arr[0]   #1st row
col3 = arr[:,2] #3rd col
row1=row1+100
col3=col3-200
arr[0]=row1
arr[:,2]=col3
ms2=op.new_sheet('m')
ms2.shape=5,5   #set same size as source mat object
ms2.from_np2d(arr)
Go to Top of Page
   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