Why is a variable undefined when trying to analyse .bat file in MATLAB? - matlab

I am really new to MATLAB. I have to use it for a project on 3D facial image analysis. I followed procedures described at Facial Landmarking Software.
I am using Windows. I get the following error message when I run compute_many.bat as required in the link:
Undefined variable "compute_many" or class "compute_many.bat".
I can see the compute_many.bat file generated in my folder from the code Get_compute_many_Windows, but I do not know why the variable is undefined.
I do not particularly understand:
Open a terminal window, cd to either the Training or Subjects directory and execute the following command to generate the .PLY files.
How to open a terminal window? Where to type compute_many.bat? Does this cause the error?

Related

Cannot create plots in Jupyter using Octave

I'm attempting to get Octave working in Jupyter and while I can execute basic math, I cannot get plots to work. Regardless of what type of graphics library I try to use, I get an error similar to this:
error: feval: function '__init_gnuplot__' not found
error: called from
graphics_toolkit at line 98 column 5
Here's the code that faileds:
register_graphics_toolkit('gnuplot');
available_graphics_toolkits()
graphics_toolkit("gnuplot");
I did some investigation and my best guess is that it looks like it's looking for a file called __init_gnuplot__.cc, based on the fact I found a file with a similar name but ends with '-tst'. However, that file doesn't exist and grepping the entire file structure under the octave directory doesn't find any instances of the function in the error.
Has Anaconda removed that functionality? Does anyone know where that '__init_gnuplot__' function is supposed to be located? Or, better yet, does anyone know how to resolve this?

How to load .mat files onto Matlab? Basically what's wrong with my code?

For this project we have been given code, and will be changing some inputs and assumptions. Thus, I already possess the original codes, but just changing all the creator's file paths to match my own computer is yielding me a lot of trouble. The following, and many variations of, continually yield errors.
load \Users\myname\Library\Documents\...
The error is
Error using load
'Unable to read file
\Users\myname\Library\Documents...'.
No such file or directory.
My files are stored in my Documents. Another person in my group on windows has used
load C:\Users\hisname\Desktop\...
Is there something I'm missing in my line, similar to the C drive but on Mac? Is my code just completely wrong, I'm able to load files in R quite easily, but Matlab is posing a huge hurdle. I have no experience with Matlab and have been asked simply to run this code.
On the Mac, path components are separated by /, not \. Thus, you should type
load /Users/myname/Documents/filename.mat
You can use the location bar at the top of the command window to change to the directory where your file is located, and then you can type
load filename
to load filename.mat.
Also, are you sure you have a Documents directory under Library? Why?
To run code from a file called "my_file.m", than just open your Matlab and type run my_file.m. This will run your script in the Command Window.
The load function is used, if you want to load a .mat file. These are normally files, where variables from your workspace are stored.

How to read Ansys data files in ParaView?

Anybody knows how to export an Ansys structural data file to ParaView?
It is read that ParaView has an Ansys reader, but it does not work. Errors always come up when loading the *.inp file.
Is there any script to convert .inp files to .vtk?
Thanks
Based on the video from Czech-based SVS FEM s.r.o., I wrote an input file for Ansys Mechanical APDL, that creates a VTK file, which can be opened in ParaView.
In the input file vtk.inp, the user has to specify the argument arg1, for which the nodal values are to be written to the vtk file via the command *get,my_results(j),NODE,n_j,..., p.e.
arg1='S,EQV' ! for equivalent stress or
arg1='TEMP' ! for temperature
For further nodal results, refer to the specifications of the *GET command in the Ansys Commands Reference.
The vtk.inp file should be placed in the current working directory. It is called with the APDL command /input,vtk,inp. In Ansys Mechanical, this command can directly be inserted in the command line. In Ansys Workbench, the command can be pasted in the feature Commands (APDL) under Solution.
The output file output.vtk is written in the same location as the input file.
The code was tested with a structural analysis in Ansys Mechanical APDL 17.2 and Ansys Workbench 17.2. The vtk file was tested with ParaView 5.4.1.
Explanation:
The array e_types_Ansys_to_VTK maps the Ansys element types (p. e. SOLID186) to VTK cell types (see also Ansys Element Types).
Limitations:
The input file is yet limited to write only one scalar parameter result in the vtk file, but it can easily be extended for vector or tensor results as well as for multiple results in one vtk file, following the VTK File Format Specification.
Since Ansys stores nodal results only in the corner nodes, only linear VTK elements are used. There could still be some minor mistakes in the e_types_Ansys_to_VTK map, since I could only test some element types. Please feel free to report any corrections or extensions to the code in the comments.
Here is the link to the source code. Use at your own risk.
In case you would like to export a vtk file directly from Ansys Workbench, a Python result converter was introduced in a Youtube video here. Unfortunately, the source code only appears in the video and is explained in Czech language.
Thus, I typewrote the code from screenshots and made some minor improvements.
You will need two files to install the macro as an Ansys ACT extension:
main.py and vtk.xml.
Place the file vtk.xml in the folder C:\Program Files\ANSYS Inc\v###\Addins\ACT\extensions, where ### is your Ansys version, p.e. 172
Create a new folder vtk in C:\Program Files\ANSYS Inc\v###\Addins\ACT\extensions.
Place the file main.py in the created folder.
Start Ansys Workbench.
Register the path C:\Program Files\ANSYS Inc\v###\Addins\ACT\extensions as additional extension path under Tools > Options > Extensions.
Restart Ansys Workbench, go to Extensions > ACT start page > Extension manager > VTK and load the extension.
In a structural analysis, go to Results, right-click and insert My results. Three inputs have to made by the user:
Under *get,my_results(j),NODE,N,..., , give the desired nodal result according to the Ansys Commands Reference, p.e. S,EQV for equivalent stress.
Under VTF file name, give the full path to the vtk output file to be created, p.e. C:\temp\output.vtk
Under Load step, give the load step number (p.e. 1 for last load step unless not stated otherwise).
For larger models, I experienced that the automatically generated file makeresult.mac is not instantly transferred from the project_pending folder to the actual working directory, thus, causing the macro to throw an error. Maybe, anyone can make a suggestion on how to fix this?
ParaView cannot read .inp structure files (I guess this is the Abaqus file format). You could try to export your files as Nastran (.nas) files, since ParaView has a Nastran reader.

MATLAB deploytool simulink Undefined function 'load_system'

I am using a MATLAB m file code which loads a simulink file, runs it and evaluats it so many times inside a complicated parallel loop.
It runs perfect at MATLAB environment. When compiling the code via deploytool command, installing it and running it from command line, I would have a difficult time.
At the line where it is loading the model,
mymodel= ... ;
load_system(mymodel);
I get the following error
C:\Program Files\mymain\application>Warning: Name is nonexistent or not a directory: model
> In path at 109
In addpath at 86
In run_main at 3
Warning: Name is nonexistent or not a directory: data
> In path at 109
In addpath at 86
In run_main at 4
Warning: Name is nonexistent or not a directory: graphics
> In path at 109
In addpath at 86
In run_main at 5
Starting parallel pool (parpool) using the 'local' profile ... connected to 2 workers.
Initializing ...
Undefined function 'load_system' for input arguments of type 'char'.
Error in run_main (line 40)
MATLAB:UndefinedFunction
I don't care about warnings (as I don't care about most of other MATLAB warnings) however I get error about not recognizing function to open a simulink model ('load_system') :
Undefined function 'load_system' for input arguments of type 'char'.
I did a search and I found the following questions:
load_system using MCR
Deployment of Simulink Models
The first link says
I just got confused: is deployment tools about compiling to C++ or to .NET ?
Is is supposed to increase speed or becomming stand-alone is the only advantage?
The problem with both links is that they talk about strategy. But how to implement them? How can I compile a MATLAB code which uses load_system and sim command to load and simulate a model?
Can anybody bring step by step solution for a very simple example of a MATLAB code (m file) simulating a model and then compiling both of them?
The first sentence of your documentation screen shot is the important one. As mentioned by #Navan (in a comment), Simulink functionality is not compatible with MATLAB Compiler. That is, any m-code that uses Simulink functinality (load_system, sim, etc) will not execute when using the MATLAB Compiler.
Assuming that you have access to Simulink Coder, and that your model doesn't contain functionality that prevents it from being converted to c-code, then your only option is to develop your application in two parts:
With your Simulink model: Use Simulink Coder to create an executable from your model. There are several examples of doing this in the doc, including Using RSIM Target for Batch Simulations. There are various command line options for passing new parameter sets and inputs to the executable via a mat file. The results of the simulation (i.e what would normally be written to the MATLAB Workspace) gets written to a mat file created by the executable.
Within you MATLAB code: replace all Simulink functionality with a call (typically using the system function, as shown in the linked example) to the executable created in step 1. Prior to this call you'll need to create a mat file with all your parameters in it; and after the call you'll want to read results from the mat file created by the executable.
It's not a trivial process, but is do-able.

MATLAB error when running the program "try.m"

After creating a MATLAB (version 2010a) file in the editor, I am getting the below mentioned error:
"MATLAB cannot run this file because \toolbox\matlab\lang\try.m shadows it in MATLAB path"
Also with this I get an option to "change folder", "add the path". Even after clicking and working around with this option I keep getting the same message.
I looked up in the matlab manual and tried to change the path. Also I checked my path variable, the place where I am storing my matlab files is already there in the path variable. Please help correcting the error. The name of my file is try.m
The code inside 'try.m' is just:
clear all;
TRY is a reserved word in MATLAB, so you shouldn't use it for your filename. Rename "try.m" to something else and you should be fine. You can do this using the "Save As" from the Editor menu and typing a different name.
Is your file in the file editor also named lang.m? Because Matlab sometimes cannot resolve scope differences between m-files in the current directory and m-files that represent built-in functions. It does not appear to be telling you that your file is not in the path; rather it seems to be saying it cannot distinguish your file from \toolbox\matlab\lang.
Can you provide more details about what your file is, such as posting the code and including the working directory name?