I'm doing with MATLAB.
I have a file named 'cobat'. Cobat is a *txt file, tab delimited, consisted of 3 coloumns, so it's a table. I load it manually into this script:
I want users browse their own file. How can I do it? Is this code correct:
[filename pathname] = uigetfile(('.txt'), 'Browse Your File')
Here are my problems:
I think it is only for text file, not tab delimited (table). I think I have to use uitable, but I don't understand how to implement it, because the file (cobat) should be loaded.
And, if it has been implemented, I can't write 'cobat' in my script, like this:
[g c] = kmeans(cobat,k,'dist','SqEuclidean'); y = [cobat g]
Then I have to change 'cobat' to what name?
Thank you.
You are on the right track. After locating the file you need to load it:
load([pathname filesep filename])
If file name is cobat (or cobat.txt), it will create a matrix called cobat in the workspace with the content of the file.
Related
Issue - I have this large batch of pdf, word & notepad files which are required to be renamed according to the text available in each file.
For eg: I have to open file A, search the entire document for the string which will be used as its name, copy, close the file and rename the file.
After searching for some while I found that autohotkey can help me with this though I'm open to every solution. What I want to do is open the file, search for the name, select the text and use the keystroke to close and rename the file.
Could anyone help me with this?
I'm not going to give you a script but what you want can be done.
You need to collect various pieces of information when you rename a file. One of them being the current file name which you can often grab from the window title. You can use https://autohotkey.com/docs/commands/WinGetTitle.htm
If a filename is wrapped in [ ] you can remove those using https://autohotkey.com/docs/commands/StringReplace.htm
If you know the file path (folder where the file resides in) you can now use https://autohotkey.com/docs/commands/FileMove.htm to rename a file and use https://autohotkey.com/docs/misc/Clipboard.htm as a variable.
You would probably like to retain the extension (.doc, .txt, .pdf) so you can use https://autohotkey.com/docs/commands/SplitPath.htm to grab it and append that to the clipboard when you rename it.
Closing a file depends on your program, sometimes you can send ctrl+w or ctrl+w or you need to use the WinClose command so you need to add in that step before you use FileMove.
Is there a simple way to change / replace the automatically generated Template Miniature with a different image.
I have checked this out for Excel 2016 but the process is similar.
First, the thumbnail is generated and part of the file. There is no official process. A description for brave Office pros is shown below.
You can do this:
First, close Excel!
Get to the location of your template
Make a copy
Rename the file extension to .zip
Unzip the file into a new folder using the Windows Zip utility
Search the tree of files for a file called thumbnail.wmf
Open PowerPoint and create an empty presentation
Use the function "Insert an Image" and add the thumbnail.wmf to the slide
Remove everything else from the slide
Try to ungroup - it fails with a message asking to convert to a drawing object
From here you have two options. Either convert, ungroup, change and proceed or throw away and create a new image from scratch.
Work on image and group your image (the old or a new one), then
Right click on the grouped image and click "Save as picture"
Choose the filetype "wmf" and name it the same as before and overwrite the existing thumbnail.wmf
Go INTO the folder using Windows Explorer of unpacked files, hit Ctrl-A (Select All)
Right click and say "Send to" --> "Compressed (zipped) folder". Give it a new name.
Hit F2 to rename the file
Remove the file extension .zip
Now, open Excel!
Hit "New", "Personal" and you see your template with your custom image in full width and height. Repeat steps 10 to 16 until you're satisfied.
Drawbacks: Once you edit your file in excel and save as template with thumbnails option (advanced properties) switched on, Excel will overwrite your custom wmf-file. You have to repeat the steps "Unpack -> Replace File -> Pack" every time.
I'll post an update once I found a better solution.
Here is an automation of the process that might help with understanding the process described in the answer.
Python 3 code snippet
import zipfile
import shutil
exfilename = 'MYTEMPLATE.xltm'
a_path='C:\\TEMP'
th_path='mythumbnail.wmf'
with zipfile.ZipFile (exfilename, 'r') as zf:
#Extract to temporary folder
zf.extractall(a_path)
#replace the thumbnail
shutil.copyfile(th_path,a_path+'\\docProps\\thumbnail.wmf')
#remake the zip as a new file
shutil.make_archive('TEMP_ARCHIVE','zip',a_path)
#rename back to original, replacing original
shutil.move('TEMP_ARCHIVE.zip',exfilename)
#clean-up temporary files
shutil.rmtree(a_path)
I have a GUI that has pushbuttons. You push the button, it allows you to choose a file to open then loads that file into the workspace using uiopen('load'). This part works fine:
Then I would like it to return the name of the file it just opened, so that I can use it for telling the next part of the program which data to look at, and to get the name of the opened file to display in an edit box in the GUI itself. First issue more vital than second. Any help would be appreciated
thanks
Actually the function 'uigetfile' is usually used for openning standard dialog box for retrieving files, and the format is like:
filename = uigetfile
or
[FileName,PathName,FilterIndex] = uigetfile(FilterSpec)
This function, displays a modal dialogbox that lists files in the current folder and enables you to selector enter the name of a file. If the file name is valid and the fileexists, uigetfile returns the file name as astring when you click Open. Otherwise uigetfile displaysan appropriate error message, after which control returns to the dialogbox. You can then enter another file name or click Cancel.If you click Cancel or close thedialog window, uigetfile returns 0.
one example could be:
[FileName,PathName] = uigetfile('*.m','Select the MATLAB code file');
Also, you can use 'uigetdir' for doing the same for directories.
In addition, you can check this link: for matlab
You can use uigetfile to get the name of the file and open it using load(filename).
I am working on a gui with guide in matlab. Inbetween I devided to name the file
different and renamed it. I also renamed all functions to the new filename in the .m file
and all objects in he .fig file.
However when I start the application I still see this error
??? Undefined function or method 'uiSchwingungen' for input arguments of type 'char'.
Error in ==>
#(hObject,eventdata)uiSchwingungen('edit1_CreateFcn',hObject,eventdata,guidata(hObject))
Where uiSchwingungen is the old not existing filename.
Where is this code section hidden (It is not in the .m file, and the .fig is binary)
You need to open the .fig in GUIDE, right click on an element (like a button), go into property browser, look for the CallBack property, click on its field to edit it, and you will find the text saying
#(hObject,eventdata)uiSchwingungen('edit1_CreateFcn',hObject,eventdata,guidata(hObject))
You will need to replace uiSchwingungen with the name name of that element (which will be in the Tag field of the Property Inspector).
Go through all the buttons, text boxes, etc., as this mistake probably will have occurred more than once.
Alright this is the text file
{'samsung','n150','jp0xtr','n570','2gb','320gb','10','w7str'};
{'samsung','n150','jp0xtr','beyaz','intel','atom','n570','66','ghz','2048mb','ddr3','320gb','10','cam','bt','w7str'};
{'samsung','n150','jp0xtr','atom','n570','66ghz','2gb','320gb','10','netbook','w7s','beyaz'};
{'samsung','n150','jp0xtr','atom','n570','66ghz','2gb','320gb','10','netbook','w7s','beyaz'};
{'samsung','n150','jp0xtr','intel','atom','n570','66ghz','2gb','320gb','10','win7starter'};
{'samsung','n150jp0xtr','n570','2g','320gb','10','w7s','beyaz'};
{'samsung','n150','jp0xtr'};
{'samsung','n150','jp0xtr'};
Now i want to load it as the below cell array
I used copy paste here but i want to do that via file reading (text file). How can i do that ? Thank you.
Just edit the text file to that it starts with C = { and also ends in } and change the extension to .m. Then run it as if it was a script from matlab command-line.
Next time do not copy and paste, use the save command as in save ('monitor-list.txt', 'C', '-ASCII'). You can then load it easily with load path-to-file.