user1238396
user1238396

Reputation: 13

MATLAB: errors using rdivide; matrix division

I reference an external txt file that is generated from a different program. It basically computes a volume for me within a certain area. I have to apply a correction to the volume depending on the day and thuis need t factor in a "bulking factor."

In the command window, I can do non_pay/2 and get my answer, but running my program through editor (see % command line), I get mrdivide or rdivide errors. I don't see how I can run the function in command window with same user input value and get an answer while in the editor, I divide by the already defined variable and received errors.

Suggestions?

%Imports the tin report data
tin = input('Enter Tin Report: ','s') ;
ref_tin = importdata(tin,' ',23);
ref = ref_tin.data;

rownum = input('Enter Row Number: ','s');

%Determines if a bulking factor is present or not
reply = input('Is there a bulking factor for this dredge area? (y/n): ', 's');
if strcmp(reply,'y')
    bulk_fctr = input('Enter Bulking Factor: ','s');
else
    bulk_fctr=1;
    disp('NO Bulking Factor')
end


%Imports conditional tin report data
[n,m] = size(ref);
cnd_tin = importdata(tin,' ',48+n);
cnd = cnd_tin.data;

%Imports tin to level data level: 52 ft
grd_tin = importdata(tin,' ',71+n*2);
grd = grd_tin.data;

%Imports tin to level data level: 53.5 ft
od_tin = importdata(tin,' ',75+n*3);
od = od_tin.data(1:n,:);

%Data to be written to production database
non_pay = round((ref(:,2)-cnd(:,2)));                  %yd^3
%non_pay2 = non_pay/bulk_fctr;
volume_removed = round((ref(:,1)-cnd(:,1))+non_pay);   %yd^3
%volume_removed2 = volume_removed./bulk_fctr;
pay_volume = round(volume_removed - non_pay);          %yd^3
area = round(ref(:,3));                                %ft^2
abv_grd = round(grd(:,1));                             %yd^3
pay_rmg = round(od(:,1));                              %yd^3

data = [volume_removed,non_pay,pay_volume,area,abv_grd,pay_rmg];

Upvotes: 1

Views: 1002

Answers (1)

tmpearce
tmpearce

Reputation: 12693

When you are asking for input for 'Enter Bulking Factor', you're getting a string since you're giving it the 's' argument. Leave that out and you'll get a value back rather than a char array.

if strcmp(reply,'y')
    bulk_fctr = input('Enter Bulking Factor: ');
else
    bulk_fctr=1;
    disp('NO Bulking Factor')
end

Edit to add: you should also add some checks to make sure input is valid.

isnumeric(bulk_fctr) && isscalar(bulk_fctr)

Upvotes: 1

Related Questions