I have a variable in the MATLAB workspace and I want to pass this variable to a function in my GUI.
How do I achieve this task?
You can use the function EVALIN in your GUI to get the value of a variable from the base workspace. The following example extracts the value of the variable A in the base workspace and places that value in the local variable B:
B = evalin('base','A');
You could, for example, have an editable text box in your GUI that allows the user to enter the name of a variable to import from the base workspace. One of your GUI functions could then read the string from the editable text box and attempt to fetch that variable from the base workspace to use in some computation:
varName = get(hEditText,'String'); %# Get the string value from the uicontrol
%# object with handle hEditText
try %# Make an attempt to...
varValue = evalin('base',varName); %# get the value from the base workspace
catch exception %# Catch the exception if the above fails
error(['Variable ''' varName ... %# Throw an error
''' doesn''t exist in workspace.']);
end
You can use SETAPPDATA (in the main workpsace) and GETAPPDATA (in GUI) functions.
If you variable is someMatrix
setappdata(0,'someMatrix',someMatrix) % in the main workspace
someMatrix = getappdata(0,'someMatrix') % in GUI
Related
Below is the code which i have been trying to address the below UseCase in JMETER.Quick help is appreciated.
Usecase:
A particular text like "History" in a page response needs to be validated and the if the text counts is more than 50 a random selection of the options within the page needs to be made.And if the text counts is less than 50 1st option needs to be selected.
I am new to Jmeter and trying to solve this usingJSR223 POST processor but somehow stuck at vars.put function where i am unable to see the desired number being populated within the V paramter.
Using a boundary extractor where match no 1 should suffice the 1st selection and 0 should suffice the random selection.
def TotalInstanceAvailable = vars.get("sCount_matchNr").toInteger()
log.info("Total Instance Available = ${TotalInstanceAvailable}");
def boundary_analyzer =50;
def DesiredNumber,V
if (TotalInstanceAvailable < boundary_analyzer)
{
log.info("I am inside the loop")
DesiredNumber = 0;
log.info("DesiredNumber= ${DesiredNumber}");
vars.put("V", DesiredNumber)
log.info("v= ${V}");
}
else{
DesiredNumber=1;
log.info("DesiredNumber=${DesiredNumber}");
vars.put("V", "DesiredNumber")
log.info("v= ${V}");
}
def sCount = vars.get("sCount")
log.info("Text matching number is ${sCount_matchNr}")
You cannot store an integer in JMeter Variables using vars.put() function, you either need to cast it to String first, to wit change this line:
vars.put("V", DesiredNumber)
to this one
vars.put("V", DesiredNumber as String)
alternatively you can use vars.putObject() function which can store literally everything however you will be able to use the value only in JSR223 Elements by calling vars.getObject()
Whenever you face a problem with your JMeter script get used to look at jmeter.log file or toggle Log Viewer window - in absolute majority of cases you will find the root cause of your problem in the log file:
I have an INPUT_IMAGE_CHECK_ALL function that takes image. In INPUT_IMAGE_CHECK_ALL there are 7 functions that image is passed to.
How do I feed images from folder 1 by 1 to the INPUT_IMAGE_CHECK_ALL function?
image = imread('6-Capmissing/capmissing-image078.jpg');
INPUT_IMAGE_CHECK_ALL(image);
INPUT_IMAGE_CHECK_ALL code:
function [ ] = INPUT_IMAGE_CHECK_ALL( image )
CHECK_FOR_CAP(image);
CHECK_FOR_NOLABEL(image);
CHECK_FOR_NOLABELPRINT(image);
CHECK_FOR_OVERFILLED(image);
CHECK_FOR_LABELNOTSTRAIGHT(image);
CHECK_FOR_UNDERFILLED(image);
end
Images that I want to feed into INPUT_IMAGE_CHECK_ALL are in folder "All" named image001 to image141.
Since you know how the name of the images you want to read (image001, image002, ... from 1 to 141) the easiest way is to use a loop in which:
build the names using the function sprintf
read the image whith the name you've build
feed your function with the image data
A possible implementation could be
for img_idx=1:141
img_name=sprintf('All/image%3.3d.jpg',img_idx)
disp(['Reading ' img_name])
the_image=imread(img_name);
INPUT_IMAGE_CHECK_ALL(the_image);
end
In the above code:
notice the format used in the call to sprintf: %3.3d: this allows padding with 0 the number in the buildoing of the filename, so that you can have 001, 002, ... 013 and so on
if the folder All in which your images are stored is not in the MatlLab path you have to specify the folder in building the filename
I've used the_image as name of the variable in which to store the data of the image because image (the varaible you are using) is a MatLab function.
the call to the disp function is used only to print on the CommandWindow a message about what the script is dooing (which image is processing); you can remove it
If the folder All only the images you you want to process, another possibility could be to get the list of images using the function dir to get the filenames of the
The function dir returns a struct in which the information about the files are stored.
In this case you have to loop over the list returned by dir
% Get the filenames of all the images in the folder "All"
img_list=dir('All/image*.jpg')
% Loops over the list of images
for img_idx=1:length(img_list)
img_name=['All/' img_list(img_idx).name]
disp(['Reading ' img_name])
the_image=imread(img_name)
INPUT_IMAGE_CHECK_ALL(the_image);
end
Hope this helps,
Qapla'
My script automates the room booking process at my school for group projects. I have created an automatic log-in script which works fine. Now I would like to access different elements from the loaded page (check boxes, radio buttons...).
How can I save various elements from the page that I have logged-in into and perform certain actions on them?
Func SignIn()
Global $window = _IECreate("https://roombooking.au.dk/classes/Login.aspx? ReturnUrl=%2fclasses%2fbook.aspx")
_IELoadWait($window)
If #error Then Return
WinSetState("[ACTIVE]", "", #SW_MAXIMIZE)
Local $username = _IEGetObjByName($window,"ctl00$Main$UsernameBox")
Local $password = _IEGetObjByName($window,"ctl00$Main$PasswordBox")
Local $button = _IEGetObjByName($window, "ctl00$Main$LoginBtn")
_IEFormElementSetValue($username,"abc")
_IEFormElementSetValue($password,"123")
_IEAction ($button, "click")
EndFunc
Func Room()
Local $SelectRoom = _IEGetObjByName(**???**,"ctl00$Main$ChangeReqsBtn")
_IELoadWait($bwindow)
_IEAction($s526,"click")
EndFunc
From the Help File:
#include <IE.au3>
_IEGetObjByName ( ByRef $oObject, $sName [, $iIndex = 0] )
$oObject Object variable of an InternetExplorer.Application, Window or Frame object
$sName Specifies name of the object you wish to match
$iIndex If name occurs more than once, specifies instance by 0-based index
0 (Default) or positive integer returns an indexed instance
-1 returns a collection of the specified objects
In your case the code will be something like:
Local $SelectRoom =
_IEGetObjByName($window,"ctl00$Main$ChangeReqsBtn")
AutoIt offers many different approaches to HTML document retrieval. Without providing concerning source code it can only be guessed.
HTML source of document is returned by _IEDocReadHTML() (assuming you're using IE.au3 UDF). Example:
#include <IE.au3>
Global Const $oIE = _IECreate('http://www.google.com/')
Global Const $sDocHTML = _IEDocReadHTML($oIE)
_IEQuit($oIE)
ConsoleWrite($sDocHTML & #LF)
Exit 0
Mentioned UDF contains functions to set values to form elements (lookup _IEForm...() in AutoIt's user defined function reference).
I'm having a problem with set function in MatLab gui I'm getting this error :
Invalid handle object.
there is my code:
[value index] = min( CostFunction(params, ...
input_layer_size, ...
hidden_layer_size, ...
num_labels, ...
X, y, lambda));
set(handles.cfwoText,????,value);
Value returned from [value index]is type double ex:1.4563e-011,and I want to show it on EditText called cfwoText,but i dont know what type should I write in ?
I believe a simple google search will provide an answer.
In addition, in GUIDE you can write click your Edit Text and choose Property Inspector. You will see all the properties.
Having said that, what you are looking for is
set(handles.cfwoText,'String',num2str(value));
Note that num2str is required since value is double and the text is string.
My question involves the use of QTP / VBScript.
Goal: From the qtp main starting file, initialize an array of classes, and pass that array as a parameter to a re-usable action via a parameter.
Problem: I am not able to pass an array of classes to my re-usable action.
Details:
I have two files: “application_main” and “personal_action”.
application_main is the entry point into qtp/vbscript.
personal_action is a re-usable action
Inside application_main, we have a call to InvokeApplication, proceeded by a few other declarations.
I am able to initialize an array and proceed to pass it as a parameter from my application_main to my personal_action:
From application_main:
Dim myArray
myArray = new Array(object1, object2, object3)
RunAction “personal_action”, oneIteration, myInteger, myBoolean, myArray
On the personal_action page, I edit the parameter properties via:
Edit->Action->ActionProperties. I select the Parameters tab.
In it, I have the option to define the amount of incoming parameters and each individual type. These available types seem to be restricted to:
String, Boolean, Date, Number, Password, Any
I set my 1st parameter as: Number
I set my 2nd parameter as: Boolean
I set my 3rd parameter as: Any
Upon running, I am prompted with this:
The type you specified for the ‘myArray’ parameter in your RunAction
statement does not match the type defined in the action.
Question: I am able to pass the Number and Boolean fine, but when an array is involved, qtp/vbscript doesn't seem to handle it well. Why am I not able to pass an array to an action via parameters from the main startup file? This seems like a common and simple task. Could I be so wrong?
Any help is appreciated. Thank you.
As per my knowledge, QTP will NOT allow this. There is no parameter type that can be used to represent an Array. This might be a limitation of QuickTest Professional.
Rather than passing array you can pass the Array elements as a string separated with delimiters.
Example:
"Item1^Item2^............" where "^" is the delimiter
then you can use split function of vb script, to get your array back.
Again doing the same thing with object,we have to give try for this
use lib file in your action ...
Create array public in lib
but in end for any case test or interation vararray=null
rodrigonw.
Sugestion... use function for include your lib in your actions (lib path)
Lib soluction
''######################################LIB"
'lib Passsagem de valores entre array
Dim arrayyy()
Sub setArrayyy(strvalores,redimencionaArray)
On error resume next
tamanho=UBound(arrayyy,1)
If Err.Number=9 then
ReDim arrayyy(0)
redimencionaArray=false
end if
err.Clear
On error goto 0
If redimencionaArray Then
tamanho=tamanho+1
ReDim preserve arrayyy(tamanho)
end if
arrayyy(tamanho)=strvalores
'arrayyy=arrayyy
End Sub
function getArrayyy() getArrayyy=arrayyy End function
''######################################"'Action X
call setArrayyy("X",false)
call setArrayyy("A",true)
call setArrayyy("D",true)
call setArrayyy("B",true)
''######################################'Action y
x=getArrayyy()
for countx=0 to ubound(x)
msgbox x(countx)
next