How to implement counter variable / function - Messages
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.sm (3 KiB) downloaded 31 time(s).
Smath does not have the push button to keep stepping from file to file.
Jean
WroteAlex,
Try this:
Alex.sm (4 KiB) downloaded 41 time(s).
Ioan
I put this also like here:
Alex2.sm (6 KiB) downloaded 33 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?
WroteNot 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.

You can try this: Alex4.sm (11 KiB) downloaded 44 time(s).
findstr(...) is because IsDefined() doesn't work as I expect inside the function, not sure if is a bug or something else.
WroteNot 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
WroteHello Alex
You can try this: Alex4.sm (11 KiB) downloaded 44 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),"+")≠-1
Thanks again, this is very clever and elegant!
WroteAlex,
I thought on a use like here:Alex3.sm (9 KiB) downloaded 39 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 :-)
WroteWroteNot 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)
WroteJean, 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
WroteWroteJean, 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.
Smath is live for Engineering/Edu/Sciemtific ...
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
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
WroteWorks 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),"+")≠-1
Thanks again, this is very clever and elegant!
You're welcome

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.
WroteFrom 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

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

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.
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.
You can test performances with this simple function: mlog.sm (3 KiB) downloaded 32 time(s).
Try to change the size of the identity matrix, a 128x128 makes the function sooooooo slow...

WroteDavide, 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).
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):
...and even bigger:
Will see if I can found some other places to improve.
Best regards.
WroteWroteDavide, 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.
-
New Posts
-
No New Posts