how to make a local variable in the "M-file" to workspace?

6 ビュー (過去 30 日間)
dong van duc
dong van duc 2012 年 10 月 10 日
回答済み: Romany George 2017 年 2 月 1 日
how to make a local variable in the "M-file" to workspace?
function [] = duong_truyen()
%
% dial_demo.m--Demonstration of dial.m.
%
% Syntax: dial_demo
% Developed in Matlab 7.6.0.324 (R2008a) on GLNX86.
% Kevin Bartlett (kpb@uvic.ca), 2008-06-20 12:03
%----------------------------------------------------------------------
open('demo_layout.fig');
set(gcf,'name','Duong Truyen');
set(gcf,'NumberTitle','off');
%----------------------------------------------------------------------
% Tao mat dong ho.
%----------------------------------------------------------------------
% Lay vi tri truc toa do
placeHolderName = 'wrapAx';
thisAx = findobj('Tag',placeHolderName); %tim kiem doi tuog co Tag la "pl...
thisPos = get(thisAx,'position'); % lay vi tri cua thisAx
delete(thisAx); %xoa thisAx
wrapDial = dial('refVal',0,... % Val_ diemef
'refOrientation',90*pi/180,... % Orientation _ su dinh huong
'valRangePerRotation',360, ... % pham vi quay
'Min',0,... % nho nhat
'Max',359,... % lon nhat
'doWrap',1,... % wrap _ bao phu
'Value',0,... % gia tri
'Position',thisPos,... % vi tri = thisPos
'VerticalAlignment','bottom',... % duowng thang dung = day, phan duoi cung
'Tag','wrapDial',... % Tag = wrapDial
'CallBack',@wrap_cb,... % goi ham "wrap_cb"
'titleStr','Keo kim quay',... % chuoi dau de (tit) = 'Wrapping' on
'titlePos','top',... % vi tri tit = dinh
'tickVals', [0 90 180 270],... % gia tri duowng tick
'tickStrs',{'N' 'E' 'S' 'W'}); % chuoi ghi o duowng tick
% Thiet lap mau.
faceColour = get(wrapDial.panelHndl,'facecolor');
set(findobj('Tag','wrapText'),'BackgroundColor',faceColour,'ForegroundColor','r');
set(findobj('Tag','wrapText'),'string','0');
% Co lai kich thuoc mat dong ho.
set(wrapDial,'dialRadius',0.55);
% Lam kim quay tuy bien.
x = [0 .55 .4 NaN .55 .4];
y = [0 0 .14 NaN 0 -.14];
set(wrapDial.linePointerHndl,'xdata',x,'ydata',y);
set(wrapDial.linePointerHndl,'color','r');
% Di chuyen ticklabel roi xa mat dong ho.
set(wrapDial,'tickLabelRadius',0.69);
% Thay doi font ticklabel.
set(wrapDial.tickLabelHndls,'fontname','Courier');
set(wrapDial.tickLabelHndls,'fontWeight','Bold');
set(wrapDial.tickLabelHndls,'fontSize',20);
%----------------------------------------------------------------------
function [] = wrap_cb()
% wrap_cb.m--Callback for "wrap" dial.
%----------------------------------------------------------------------
wrapDial = dial.find_dial('wrapDial','-1');
dialVal = round(get(wrapDial,'Value'));
set(findobj('Tag','wrapText'),'string',sprintf('%d',dialVal));
how to make a local variable "dialVal" to workspace?

採用された回答

Robert Cumming
Robert Cumming 2012 年 10 月 10 日
assignin ( 'base', 'dialVal', dialVal )
  2 件のコメント
dong van duc
dong van duc 2012 年 10 月 11 日
thankyou very much
dong van duc
dong van duc 2012 年 10 月 12 日
how to include value "dialVal" in block "from workspace" in the Simulink

サインインしてコメントする。

その他の回答 (2 件)

Sachin Ganjare
Sachin Ganjare 2012 年 10 月 12 日
"how to include value "dialVal" in block "from workspace" in the Simulink"
You can directly use dialVal directly as it is present in workspace after assignin operation, if I understand your question correctly.
  1 件のコメント
dong van duc
dong van duc 2012 年 10 月 12 日
編集済み: per isakson 2016 年 3 月 9 日
Yes, after assignin operation, "dialVal" is present in workspace, but I have a error when I write "dialVal" into block " From workspace" :
"Invalid matrix-format variable specified as workspace input in 'untitled/From workspace'. The matis must have tow dimensions and at least two columns. Comples signals of any data type and non-double real signals must be in structure format. The first column must contain time values and the remaining columns the data values"

サインインしてコメントする。


Romany George
Romany George 2017 年 2 月 1 日
Please,help me i have a Matlab Simulink Model which it`s output is Error .This output (error) I have to minimize it( USING GENETIC ALGORITHM ) by controlling three variables(Kp& ki& Kd) which included in the output.Due to this variables I can`t scope the output,and call this output in an M File
Can any one help me please to call this output in an M File. Thanks

カテゴリ

Help Center および File ExchangeAudio I/O and Waveform Generation についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by