کلیدستان

نسخه‌ی کامل: مشکل در استفاده از Input
شما در حال مشاهده نسخه آرشیو هستید. برای مشاهده نسخه کامل کلیک کنید.
سلام;
من دارم یه m-file می نویسم برای رسم پتانسیل بین 4 تا سطح که شرایط مزری رو بگیره پتانسیل بین 4 تا سطح رو رسم کنه. زیاد با قسمت m-file متلب کار نکردم برا همین اومدم از pdetool box با یه شرایط مرزی یه شکل رسم کردم بعد m-file اون رو ادیت کردم و 6 تا Input بهش اضافه کردم 2 تا برای فاصله بین سطوح و 4 تا هم شرایط مرزی ( اختلاف پتانسیل 4 سطح ) ، به جای شرایط مرزی توی m-file هم مقدار های Input رو گذاشتم . 

قسمت مشکل داره  کار :

کد:
% Input Boundary Conditions:
v1=input('Enter Potentional V1 :');
v2=input('Enter Potentional V2 :');
v3=input('Enter Potentional V3 :');
v4=input('Enter Potentional V4 :');

% Boundary conditions:
pdetool('changemode',0)
pdesetbd(4,'dir',1,'1','v4')
pdesetbd(3,'dir',1,'1','v3')
pdesetbd(2,'dir',1,'1','v1')
pdesetbd(1,'dir',1,'1','v2')

توی قسمت Boundary Conditions دقیقا V1 , V2 , V3 , V4 رو توی رسم شکل میذاره یعنی مقادیری که جای V1 ,V2 ,V3 ,V4 داره Input میشه رو نمیذاره.

لطفا راهنمایی کنید ، کامندی که برای ورود اطلاعات استفاده میشه باید تغییر کنه یا نحوه استفاده از اطلاعات وارد شده غلط هستش ....
اگر کسی قبلا مشابه این کار رو انجام داده m-file اش رو قرار بده استفاده کنیم . ممنون.

خیلی بد توضیح دادم ، امیدوارم متوجه منظورم بشید . 
سلام.
لطفا مقادیری که برای V1 تا V4 وارد می کیند را بفرمایید، چون من چند بار مقادیری را وارد کردم، اما مرتب خطا می دهد.


 
فکر کنم متوجه منظورم نشدید ، این چیزیه که تا الآن بهش رسیدم :

کد:
function potenv2

% Potencial or Electrical Chart Selection:
t=input('Enter 1 for Potencial or 2 for Electrical chart :');

% Input Boundary Conditions:
x=input('Enter a :');
y=input('Enter b :');
v1=input('Enter Potentional V1 :');
v2=input('Enter Potentional V2 :');
v3=input('Enter Potentional V3 :');
v4=input('Enter Potentional V4 :');

% Coordinates
[pde_fig,ax]=pdeinit;
pdetool('appl_cb',5);
set(ax,'DataAspectRatio',[1 2 1]);
set(ax,'PlotBoxAspectRatio',[1.5 1 1]);
set(ax,'XLim',[0 x+1]);
set(ax,'YLim',[0 y+1]);
set(ax,'XTickMode','auto');
set(ax,'YTickMode','auto');

% Geometry description:
pderect([x+0.5 0.5 y+0.5 0.5],'R1');
set(findobj(get(pde_fig,'Children'),'Tag','PDEEval'),'String','R1')

% Boundary conditions:
pdetool('changemode',0)
pdesetbd(4,'dir',1,'1','v4')
pdesetbd(3,'dir',1,'1','v3')
pdesetbd(2,'dir',1,'1','v1')
pdesetbd(1,'dir',1,'1','v2')

% Mesh generation:
setappdata(pde_fig,'Hgrad',1.3);
setappdata(pde_fig,'refinemethod','regular');
setappdata(pde_fig,'jiggle',char('on','mean',''));
pdetool('initmesh')

% PDE coefficients:
pdeseteq(1,'1.0','0.0','0','1.0','0:10','0.0','0.0','[0 100]')
setappdata(pde_fig,'currparam',['1.0';'0 '])

% Solve parameters:
setappdata(pde_fig,'solveparam',...
str2mat('0','1000','10','pdeadworst',...
'0.5','longest','0','1E-4','','fixed','Inf'))

% Plotflags and user data strings:
if t==1;
setappdata(pde_fig,'plotflags',[1 1 1 1 1 1 7 1 0 0 0 1 1 0 0 0 0 1]);
setappdata(pde_fig,'colstring','');
setappdata(pde_fig,'arrowstring','');
setappdata(pde_fig,'deformstring','');
setappdata(pde_fig,'heightstring','');
elseif t==2;
setappdata(pde_fig,'plotflags',[1 1 1 1 1 1 7 1 0 0 0 1 0 0 0 1 0 1]);
setappdata(pde_fig,'colstring','');
setappdata(pde_fig,'arrowstring','');
setappdata(pde_fig,'deformstring','');
setappdata(pde_fig,'heightstring','');
end

% Solve PDE:
pdetool('solve')

m-file بدون ارور لود میشه و مقادیر ورودی رو هم میگیره ، t , x, y رو کاری که باید باهاشون انجام بده رو انجام میده ولی V1 تا V4 هر مقداری که وارد میکنم اعمال نمیکنه دقیقا به جای اونها V1 , V2 , V3 , V4 رو میزاره توی شرایط مرزی PDE Toolbox.
یعنی اگر شما برا مثال به V1=2 , V2=3 , V3=3 , V4=2 رو به عنوان ورودی بگذارید ، میاد V1=V1 , V2=V2 , V3=V3 , V4=V4 رو میگذاره . 
سوال من در اصل اینه که چطوری ورودی Input رو بین '' قرار بدم. مثلا چطوری وقتی V1 رو میگیره :

کد:
v1=input('Enter Potentional V1 :');

بیاد مقدار وارد شده رو جای V1 که در زیر براش تعریف شده بگذاره :

کد:
pdesetbd(2,'dir',1,'1','v1')

فکر کنم الآن دیگه کاملا متوجه منظورم شدید . 
من مقادیر زیر را وارد می کنم :

کد:
Enter 1 for Potencial or 2 for Electrical chart :1
Enter a :2
Enter b :2
Enter Potentional V1 :2
Enter Potentional V2 :3
Enter Potentional V3 :3
Enter Potentional V4 :2

و با خطای زیر روبرو می شوم :


کد:
??? Error using ==> Untitled4 at 45
Error using ==> vertcat
CAT arguments dimensions are not consistent.

در صورتی که شما گفتید خطایی به وجود نمی آید.  احتمالا مقادیر نامناسبی انتخاب می کنم.
متغیرهای v1 تا v4 به درستی تعریف می شوند (در Workspace مقادیرشان را ببینید) و مشکل باید از کدهای بعد از آنها باشد (بعد از دستورهای input).

همچنین، دستور را به صورت زیر به کار ببرید، شاید درست شود (یعنی علامت های ' را از دو طرف نام متغیر بردارید) :

کد:
pdesetbd(2,'dir',1,'1',v1)

ایراد از مقادیری که وارد میکنیم نیست ، مقادری ورودی شرایط مرزی ما هستن چه مثبت ، منفی ، عدد های خیلی بزرگ ، کوچیک یا اعشاری و .... هیچ خللی در روند کار ایجاد نمیکنه . اروری که به من میده اینه :




کد:
invalid expression 'v2' when evaluating boundary conditions

چون میاد دقیقا عبارت v1 رو میگذاره جای که براش تعریف شده فقط کمیت اسکالر اونجا وارد بشه . به جا اینکه مقادیر ورودی V1 تا V4 رو وارد کنه خودشون رو میگذاره .

[عکس: l3ctubnt3zk2yh7bbk91.jpg]
کاری که فرمودید در رابطه با حذف کردن '' قبلا انجام دادم که خودش یه ارور دیگه به دنبال داره ، در رابطه با ارور شما هم فک می کنم اگر m-file زیر رو استفاده کنید فیکس میشه .




کد:
function poten

% Potencial or Electrical Chart Selection:
t=input('Enter 1 for Potencial or 2 for Electrical chart :');

% Input Boundary Conditions:
x=input('Enter a :');
y=input('Enter b :');
v1=input('Enter Potentional V1 :');
v2=input('Enter Potentional V2 :');
v3=input('Enter Potentional V3 :');
v4=input('Enter Potentional V4 :');

% Coordinates
[pde_fig,ax]=pdeinit;
pdetool('appl_cb',5);
set(ax,'DataAspectRatio',[1 2 1]);
set(ax,'PlotBoxAspectRatio',[1.5 1 1]);
set(ax,'XLim',[0 x+1]);
set(ax,'YLim',[0 y+1]);
set(ax,'XTickMode','auto');
set(ax,'YTickMode','auto');

% Geometry description:
pderect([x+0.5 0.5 y+0.5 0.5],'R1');
set(findobj(get(pde_fig,'Children'),'Tag','PDEEval'),'String','R1')

% Boundary conditions:
pdetool('changemode',0)
pdesetbd(4,...
'dir',...
1,...
'1',...
'v4')
pdesetbd(3,...
'dir',...
1,...
'1',...
'v3')
pdesetbd(2,...
'dir',...
1,...
'1',...
'v1')
pdesetbd(1,...
'dir',...
1,...
'1',...
'v2')

% Mesh generation:
setappdata(pde_fig,'Hgrad',1.3);
setappdata(pde_fig,'refinemethod','regular');
setappdata(pde_fig,'jiggle',char('on','mean',''));
pdetool('initmesh')

% PDE coefficients:
pdeseteq(1,...
'1.0',...
'0.0',...
'0',...
'1.0',...
'0:10',...
'0.0',...
'0.0',...
'[0 100]')
setappdata(pde_fig,'currparam',...
['1.0';...
'0 '])

% Solve parameters:
setappdata(pde_fig,'solveparam',...
str2mat('0','1000','10','pdeadworst',...
'0.5','longest','0','1E-4','','fixed','Inf'))

% Plotflags and user data strings:
if t==1;
setappdata(pde_fig,'plotflags',[1 1 1 1 1 1 7 1 0 0 0 1 1 0 0 0 0 1]);
setappdata(pde_fig,'colstring','');
setappdata(pde_fig,'arrowstring','');
setappdata(pde_fig,'deformstring','');
setappdata(pde_fig,'heightstring','');
elseif t==2;
setappdata(pde_fig,'plotflags',[1 1 1 1 1 1 7 1 0 0 0 1 0 0 0 1 0 1]);
setappdata(pde_fig,'colstring','');
setappdata(pde_fig,'arrowstring','');
setappdata(pde_fig,'deformstring','');
setappdata(pde_fig,'heightstring','');
end

% Solve PDE:
pdetool('solve')

در کل مشکل من فقط با دونستن یه چیز حل میشه ، اونم اینکه چطوری میشه ورودی Input رو توی '' استفاده کرد .

لطفا اگر m-file مشابه این کار دارید اینجا قرار بدید تا ازش الهام بگیریم برا این کار.خیلی ممنون .