Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline Alex M.  
#1 Posted : 24 February 2016 21:37:37(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Would anyone know if there is a way to define a variable or a function that increases in value by 1 every time it is called?

I am trying to set up automatic naming scheme for the image output of my excel_PNG plugin. It takes a filepath as an input to be used when saving generated png. What i need is to generate the filepath string which is different every time its called. It also needs to be consistent (i.e it cannot change for a particular function call every time worksheet is calculated) so random() will not work.

Ideas? Unique consistency of the value for a certain position within workbook is s the goal.

Here what i tried, predictably without success.

ID.png

ID.sm (4kb) downloaded 15 time(s).

Edited by user 24 February 2016 21:42:59(UTC)  | Reason: Not specified

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline Jean Giraud  
#2 Posted : 24 February 2016 22:54:24(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Not very clear as you don't seem to search for a specific file.
Smath does not have the push button to keep stepping from file to file.

Jean
Offline Alex M.  
#3 Posted : 24 February 2016 23:41:06(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Originally Posted by: ioan92 Go to Quoted Post
Alex,

Try this:
Alex.sm (5kb) downloaded 22 time(s).

Ioan



I put this also like here:
Alex2.sm (7kb) downloaded 20 time(s).


Thank you, Ioan, this might be my best bet. Not ideal though because it does require my input; I have about 100 calls to excel_PNG in one file, each of the call generates a PNG file, and it can be cumbersome to change the id variable for each of them.

So i take there is no "counter" function in SMath is there?

Offline Alex M.  
#4 Posted : 24 February 2016 23:43:57(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
Not very clear as you don't seem to search for a specific file.
Smath does not have the push button to keep stepping from file to file.

Jean


Jean, what I want is a function that generates an incrementally different, non random value every time its called.
Offline Davide Carpi  
#5 Posted : 25 February 2016 00:58:06(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,652
Man
Italy
Location: Italy

Was thanked: 1339 time(s) in 878 post(s)
Hello Alex Good

You can try this: Alex4.sm (12kb) downloaded 27 time(s).

findstr(...) is because IsDefined() doesn't work as I expect inside the function, not sure if is a bug or something else.

Edited by user 25 February 2016 01:05:28(UTC)  | Reason: Not specified

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 3 users thanked Davide Carpi for this useful post.
on 25/02/2016(UTC),  on 25/02/2016(UTC),  on 25/02/2016(UTC)
Offline Jean Giraud  
#6 Posted : 25 February 2016 02:14:41(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: Alex.M Go to Quoted Post
Not ideal though because it does require my input


Whether via the mouse [slider] or finger [keyboard], it rquires your input.
What I don't understand is: why don't you use IrfanView, much simpler, click
on the arrow thumbnail <= ... => There are dozens of this gadgets.
IrfanView will let you capture portion of the image +++

Jean


thanks 1 user thanked Jean Giraud for this useful post.
on 25/02/2016(UTC)
Offline Alex M.  
#7 Posted : 25 February 2016 02:15:12(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Originally Posted by: Davide Carpi Go to Quoted Post
Hello Alex Good

You can try this: Alex4.sm (12kb) downloaded 27 time(s).

findstr(...) is because IsDefined() doesn't work as I expect inside the function, not sure if is a bug or something else.


Works great, thank you very much! I almost thought it is not possible hehe.

Now I do not quite get how the if() loop works, and why does it work, and why it shall not be equal to -1. Could you walk me through this line of code, explaining what it does exactly?

findstr(num2str(id+1),"+"Wink≠-1

Thanks again, this is very clever and elegant!
Offline Alex M.  
#8 Posted : 25 February 2016 02:16:52(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Originally Posted by: ioan92 Go to Quoted Post
Alex,

I thought on a use like here: Alex3.sm (10kb) downloaded 19 time(s).
You have the file name as you need (?) containing a variable.


Thank you Ioan, your function incorporates "current folder" very nicely - will use it in my worksheets, if you do not mind :-)
Offline Alex M.  
#9 Posted : 25 February 2016 02:18:01(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
Originally Posted by: Alex.M Go to Quoted Post
Not ideal though because it does require my input


Whether via the mouse [slider] or finger [keyboard], it rquires your input.
What I don't understand is: why don't you use IrfanView, much simpler, click
on the arrow thumbnail <= ... => There are dozens of this gadgets.
IrfanView will let you capture portion of the image +++

Jean






Jean, if you can tell me exactly what you do not understand about what I would like to do I will gladly explain it ( I did not quite get it from your post)
Offline Alex M.  
#10 Posted : 25 February 2016 02:19:29(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Well my headache was solved by Davide and Ioan, thank you guys!
Offline Jean Giraud  
#11 Posted : 25 February 2016 02:34:22(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: Alex.M Go to Quoted Post
Jean, if you can tell me exactly what you do not understand about what I would like to do I will gladly explain it ( I did not quite get it from your post)


From Ioan & Davide, it's OK to view image in Smath, but useless as you can't
further process/select ... etc. You can "fmap vectorise", scale the grayscale
but can't scale RGB replot because Smath does not have the "Picture operator".

Jean

Offline Alex M.  
#12 Posted : 25 February 2016 02:41:13(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
Originally Posted by: Alex.M Go to Quoted Post
Jean, if you can tell me exactly what you do not understand about what I would like to do I will gladly explain it ( I did not quite get it from your post)

it's OK to view image in Smath, but useless as you can't
further process/select ... etc.



From perspective of a person who prepared about 1200 pages of calculation books over past year only I can tell that it is very important (for me) to view pictures in the calcbooks without further processing. I could not care less to perform linear algebra on them. For me they are just sketches, not matrices.

Cheers,


Alex M.
Offline Jean Giraud  
#13 Posted : 25 February 2016 07:30:04(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
I understand your point of storing dead stuff...
Smath is live for Engineering/Edu/Sciemtific ...


Image W truss.gif


What's the point to read that dead image if the construction is not exemplified ?
There was a long thread on that one, particularly about not a "parrot plot"...
Maybe not yet finished ! ? I admit, humbly, I'm not a "bright spark".

Jean
thanks 1 user thanked Jean Giraud for this useful post.
on 25/02/2016(UTC)
Offline Jean Giraud  
#14 Posted : 25 February 2016 08:36:03(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
... preferences aren't arguable. If I need an image in an Smath work sheet,
for instance a source image from reference, I save it *.GIF [256].
Bad luck, Smath does not open *.gif [not 24/32 bbp]. Why should I kneel down
and restrict myself because of Smath. Open my image in IrfanView, copy/paste
in Smath ... job done little memory, much faster than waiting Smath opens
an *.BMP or *.PNG. There are many ways to skin a cat [I didn't invent].

Jean
Offline Davide Carpi  
#15 Posted : 25 February 2016 12:53:43(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,652
Man
Italy
Location: Italy

Was thanked: 1339 time(s) in 878 post(s)
Originally Posted by: Alex.M Go to Quoted Post
Works great, thank you very much! I almost thought it is not possible hehe.

Now I do not quite get how the if() loop works, and why does it work, and why it shall not be equal to -1. Could you walk me through this line of code, explaining what it does exactly?

findstr(num2str(id+1),"+"Wink≠-1

Thanks again, this is very clever and elegant!

You're welcome Happy

The function uses pass-by-reference to output the value to the canvas via the input argument.
If the input value is an unknown, will be set to 1. This should be done in the if/else statement using the built-in ¬IsDefined(id) that for some reason I have to investigate doesn't works, so I've replaced it with findstr(num2str(id+1),"+")≠-1
num2str(id+1) converts the input in a math string -> id+1 will be converted in a number and then in a string if the input argument is a number, otherwise will be "something+1" where something is the name of the input unknown in the canvas (because id is a local name that contains the variable passed from the canvas -> a simple num2str(id)≡"id" is not possible); in the first case, findstr will returns -1, because the string contains a number, in the second case will returns a vector that contains the index of each "+" match. Hence if findstr(...)≠-1 -> the variable is not a number, set it to 1, otherwise increment by one.


Originally Posted by: Jean Giraud Go to Quoted Post
From Ioan & Davide, it's OK to view image in Smath, but useless as you can't
further process/select ... etc. You can "fmap vectorise", scale the grayscale
but can't scale RGB replot because Smath does not have the "Picture operator"

Jean, I think that both the purposes are OK and can/must coexist Good

If one needs only to show an image on the canvas, there's no need to fill the worksheet memory or the file itself of useless data.

If one want/needs to process images, this is another story (BTW, many thanks for all the worksheets you share here in the forum Thank you )
IMHO as it is now processing images on the worksheet is reliable only for small images (only teaching purposes); using plugins you can boost the math speed or build a region that can do all "in-place" but this is not funny because the math is hidden under the hood. A "picture operator" or a boost in matrices management is needed and can be done only by Andrey (here we are focusing on images but the issue may be the same in any signal processing problem, such as audio, wind, etc...).

The example below is ok for a 128x128 image, but too slow for a 256x256 image (or bigger), using greyscale images, and functions driven in plugin: fftmagnitude (abs() extended to matrices), fftphase (arg() extended to matrices), fftlog (basically a logarithm function for matrices); to run all except the ffts in the canvas (in a reasonable time) 128x128 is too big.
2016-02-25 10_46_19-SMath Studio Desktop - [shift.sm_].png

Edited by user 25 February 2016 18:18:37(UTC)  | Reason: Not specified

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
Offline Alex M.  
#16 Posted : 25 February 2016 16:35:10(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Davide, thank you for explanation, very useful.

I would agree with Davide that it is not the lack of picture operator, but the lack of processing horsepower that makes any sort of image/signal processing impossible in SMath. Right now it takes good 8 seconds just to display a 1000x2000 matrix in the worksheet. And than it lags when you scroll said worksheet as well..

Davide, was this ever brought up to Andrey? Matrix manipulation is an important bit for practical use of SMath and right now it is on a slower side.
Offline Davide Carpi  
#17 Posted : 25 February 2016 18:15:37(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,652
Man
Italy
Location: Italy

Was thanked: 1339 time(s) in 878 post(s)
Maybe, not yet from my side... about the displaying issues I've made a request in the BTS recently (SS-2291)

You can test performances with this simple function: mlog.sm (4kb) downloaded 16 time(s).
Try to change the size of the identity matrix, a 128x128 makes the function sooooooo slow... Wallbash

Edited by user 25 February 2016 18:40:17(UTC)  | Reason: Not specified

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
Offline Andrey Ivashov  
#18 Posted : 25 February 2016 23:59:28(UTC)
Andrey Ivashov


Rank: Administration

Groups: Developers, Registered, Knovel Developers, Administrators, Advanced Member
Joined: 11/07/2008(UTC)
Posts: 1,616
Man
Russian Federation

Was thanked: 1978 time(s) in 666 post(s)
Originally Posted by: Alex.M Go to Quoted Post
Davide, was this ever brought up to Andrey? Matrix manipulation is an important bit for practical use of SMath and right now it is on a slower side.

Thank you for noting this. Just reviewed a code and found possibility to make great improvement to some operations with matrices.

This is latest available public build of SMath Studio (see the calculation time).
matrix_speed_test_1.png

This is a new build I've just created locally (changes not related to matrix() function - the overall speed of communication between SS Core and built-in symbolic library improved):
matrix_speed_test_2.png

...and even bigger:
matrix_speed_test_3.png

Will see if I can found some other places to improve.

Best regards.
thanks 4 users thanked Andrey Ivashov for this useful post.
on 26/02/2016(UTC),  on 26/02/2016(UTC),  on 26/02/2016(UTC),  on 26/02/2016(UTC)
Offline Alex M.  
#19 Posted : 26 February 2016 00:05:38(UTC)
Alex M.


Rank: Advanced Member

Groups: Registered
Joined: 03/03/2014(UTC)
Posts: 418
Canada

Was thanked: 125 time(s) in 96 post(s)
Originally Posted by: Andrey Ivashov Go to Quoted Post
Originally Posted by: Alex.M Go to Quoted Post
Davide, was this ever brought up to Andrey? Matrix manipulation is an important bit for practical use of SMath and right now it is on a slower side.

Thank you for noting this. Just reviewed a code and found possibility to make great improvement to some operations with matrices.

Will see if I can found some other places to improve.

Best regards.


Andrey, this is incredible!

If you can make matricies fly (both calcs and UI / scrolling lag) its a huge-huge plus; this will opens doors to do "real" structural analysis, signal processing, image manipulations... Our digital world is made of matricies!

Thank you very much

Alex M.

Edited by user 26 February 2016 00:11:33(UTC)  | Reason: Not specified

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.