Undefined operator '/' for input arguments of type 'cell'.

Please help me I am a beginner. This code gives me error kindly spot the issue
syms Area length cost
prompt = {'Please Enter Value of Area in feet:'};
dlgtitle = 'Input Area';
dims = [1 45];
%k= input(prompt)
answer = inputdlg(prompt,dlgtitle,dims);
k = answer;
Area = k;
width = 20;
width = num2cell(width);
length = Area./width;
cost = 49.75.*length+ 30.*width;

 採用された回答

Image Analyst
Image Analyst 2020 年 12 月 14 日

2 投票

Quite a few errors there. See below for the correct version:
% syms Area length cost % Not needed to declare as syms
prompt = {'Please Enter Value of Area in feet:'};
dialogTitle = 'Input Area ';
numLines = [1, 45];
userResponse = inputdlg(prompt, dialogTitle, numLines);
% Extract Area from the cell array. It will be a character so we need to call str2double().
Area = str2double(userResponse{1});
% Compute the other things.
width = 20;
theLength = Area / width;
cost = 49.75 * theLength + 30 * width;
% Show user the results.
fprintf('Area = %f square feet.\nWidth = %f feet.\nLenth = %f feet.\nCost = $%f.\n',...
Area, width, theLength, cost);
Don't declare as syms. Don't use the name of a built-in function, such as length, as a variable name.

1 件のコメント

Salman Ahmed
Salman Ahmed 2020 年 12 月 14 日
Thank you so much for Helping

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

その他の回答 (1 件)

VBBV
VBBV 2020 年 12 月 13 日

1 投票

%rue
width = 20;
% width = num2cell(width);
Comment the num2cell line and try again

9 件のコメント

Salman Ahmed
Salman Ahmed 2020 年 12 月 13 日
its giving the same error again
VBBV
VBBV 2020 年 12 月 13 日
編集済み: VBBV 2020 年 12 月 13 日
Did you clear the input variables after changes?
VBBV
VBBV 2020 年 12 月 13 日
Use str2num to convert the input valued to numeric before performing the ./ operation
VBBV
VBBV 2020 年 12 月 13 日
編集済み: VBBV 2020 年 12 月 13 日
%true
width = 20;
width = num2cell(width)
length =str2num(Area)./str2num(width)
cost = 49.75.*length+30.*str2num(width)
Salman Ahmed
Salman Ahmed 2020 年 12 月 13 日
this works but value of length and width is set to NaN.
VBBV
VBBV 2020 年 12 月 14 日
What were your input values for Area ?
VBBV
VBBV 2020 年 12 月 14 日
編集済み: VBBV 2020 年 12 月 14 日
Did it contained any characters?
%rue
width = str2num(width);
cost = 49.75.*length+30.*(width)
VBBV
VBBV 2020 年 12 月 14 日
%true
width = 20;
width = num2cell(width)
Tlength =str2num(Area)./str2num(width)
cost = 49.75.*Tlength+30.*str2num(width)
Sorry, you have used builtin function length as variable to store values. Please change it to as above or something other than standard functions of matlab.
Salman Ahmed
Salman Ahmed 2020 年 12 月 14 日
I changed the name now it works fine thank you so much for helping

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

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by