Creating an instance of a class - matlab

Trying to create my first class in MATLAB but obviously am missing something.
So here is my class below.
classdef MyBank
properties
Balance;
CustName;
end
methods
function BA = MyBank()
BA.Balance = 0;
BA.CustName = 'Mr Blogs'
end
end
end
In the same path I have a m file. In this file I try to create an object from my class like so,
bank = MyBank;
I get the error message 'undefined function or variabel 'MyBank'? Not sure what I'm missing as the examples I have seen appear to do the same thing?
Also when typing BA in my constructor should there be any intellisense? Find it quite painful coding in Matlab.

Matlab doesn't understand ".
You shuold use BA.CustName = 'Mr Blogs'
Are you using Matlab or Octave? Octave understands ", but last time I checked classdef is not working.
To find the constructor with "intellisense", you should type "My" and then press tab. At least for me this works.
If this doesn't work for you, check that your file is named MyBank.m and double check if it is in your current working folder. Open the file in your edior window and execute it by pressing F5. Then a dialog should pop up, if your in another working directory.

Related

2 problem with minspantree.m in Matlab 2018a

2 problem with minspantree.m in Matlab 2018a
Hi dear all; I want to find a min-span-tree of a matrix. I figured that MATLAB's own minspantree.m may be the most efficient algorithm. So i use
open minspantree.m
And here comes Question:
1.The code in minspantree.m used G.EdgeProperties.Weight and G.Underlying. G is a graph object. But when I use G.EdgeProperties.Weight or G.Underlying in Command window, both returns error: Error using graph/subsref (line 15) No public property 'EdgeProperties' for class 'graph'. Why?
2.minspantree.m line 62:
[pred, edgeind] = primMinSpanningTree(G.Underlying, w, rootNode, restart);
Is primMinSpanningTree a function? But I can not find any: function [ ] = primMinSpanningTree() in minspantree.m, neither can I find primMinSpanningTree.m file in my whole disk. So what is primMinSpanningTree? What is its code? How can I find it and open it?
Thanks all very much.
Both EdgeProperties and Underlying are private properties of the graph class. They can only be accessed from within the class. Take a look at Graph.m. minspantree is a class method, so it has access.
primMinSpanningTree is a built-in method from matlab.internal.graph.MLGraph. You can see that with which primMinSpanningTree. So I believe the code might not be accessible.

Adding another function in an "App Designer" function

I'm using App Designer in MATLAB. I have created a push button, 51-54 work no problem, then when I assigned another function into it (highlighted in the screenshot), it wouldn't work!
Please help me overcome this problem.
Screenshot showing the problem:
Problem: function inside of a function the way it is written in the screenshot.
4 things come up my mind:
Generally:
yourApp.mlapp or any other code.m file
function someProcess()
end
function subProcess()
end
In your case rather try to write your function in an second .m file and call it from within your your app.
be sure to have it on the MATLAB path.
yourApp.mlapp or any other code.m file
function someProcess()
subProcess();
end
+ external code.m file
function someProcess()
subProcess();
end
define your function as a public or private function (method) inside the app. ( for others: the block is not there by default. click: app designer> code view > function > add private function | add public function)
screenshot
if your function is only used once you could also write an anonymous function
https://www.mathworks.com/help/matlab/matlab_prog/anonymous-functions.html

MATLAB superclass can not be found on the MATLAB's search path

I have 2 paths :
C:\controller\functions\verifyModel.m
C:\OGVD\prod\KMLP\controller\controllerStatus.m
verifyModel.m
classdef verifyModel
methods(access=public)
function...
end
end
controllerStatus.m
classdef controllerStatus < verifyModel
.....
end
but when I run controllerStatus.m, I got an error as the class I used isn't in the path
how could I add verifyModel to the path ?
Before usage of controllerStatus use:
addpath('C:\controller\functions\')
Also, you might want to put in in a # folder. These folders are added to the path whenever they are visible, so as they are a subfolder of your current path(pwd).
Or add 'C:\controller\functions\' to your static matlab path, what I do not recommend.
See also this answer.

Which file contains function of core/session in magento?

I need to customize other's code,
so I found they used
Mage::getSingleton('core/session')->getMyCustomBlockInfo();
in Order.php file for custom order email
so I can't find this function getMyCustomBlockInfo();
Can anyone tell me where this function reside?
Thanks
those are magic functions get() and set() and you are asking a session variable there that is set as
Mage::getSingleton('core/session')->setMyCustomBlockInfo();
somewhere in your code. If you use terminal you can easily find by making a following grep:
grep '>setMyCustomBlockInfo(' . -rsni
and it will list the files where your variable is set to session.
example :
Mage::getModel('catalog/product'); //or
Mage::getSingleton('catalog/product');
the code must be in '../app/core/Mage/Catalog/Model/Product.php' file
then
Mage::getSingleton('core/session');
the code must be in '../app/core/Mage/Core/Model/Session.php' file
because the class Mage_Core_Model_Session's parent::parent is Varien_Object, then you can do all magic functions and you can ->getData() to see the Data inside.
Mage::getSingleton('core/session')->getData();
on your problem when go call ->getData() you can see data : [my_custom_block_info]
you can set it with call
Mage::getSingleton('core/session')->setMyCustomBlockInfo('what');
Mage::getSingleton('core/session')->getMyCustomBlockInfo();
// will return 'what'

IronPython error, "'TextBox' object has no attribute 'text'" when using a ShowDialog() method created in SharpDevelop

I am trying to call a form designed in SharpDevelop within another IDE. I get the following error message: 'TextBox' object has no attribute 'text'. This happens when I run the script which includes the lines shown below in the other IDE. Is the problem in the script itself or in the Form1 class written in SharpDevelop? How can I resolve this?
import myform
import System
f = myform.Form1()
if f.ShowDialog() == System.Windows.Forms.DialogResult.OK:
dx = f._directionx.text
dy = f._directiony.text
dz = f._directionz.text
nb = f._nbofiterations.text
w = f._width.text
h = f._height.text
Since it appears that you're using IronPython (the System.Windows.Forms gave it away) I'm guessing that your TextBox is a Forms element.
If this is so, you need the .Text property - everything (properties, functions/methods that I know of) in the .NET library starts with an uppercase letter.
change .text to .Text
dx = f._directionx.Text
and so on
C sharp is case sensitive language