Object oriented Programming problem

2 次查看(过去 30 天)
MRF
MRF 2020-11-21
编辑: MRF 2020-11-21
I need to save ans as boreSegments .
D = 4.0;
H_boreholes = [75.0, 100.0, 125.0, 150.0, 75.0];
y = 0;
r_b = 0.075;
nSegments = 12;
B = 7.5;
for i = 1: size(H_boreholes,2)
H(i) = (H_boreholes(1,i));
x(i) = (i*B);
borefield(i,:) = boreholes (H(i) ,D ,r_b ,x(i), y);
end
boreSegments = boreholesegments(borefield, nSegments);
function boreSegments = boreholesegments(borefield, nSegments)
for j = 1:size(borefield,1)
for i = 1:nSegments
H = borefield(j).H / nSegments;
D = borefield(j).D + i * borefield(j).H / nSegments ;
ans = boreholes... % <<<<<<<<<<<<<<
(H ,D,borefield(j).r_b,borefield(j).x,borefield(j).y) % <<<<<<<<<<<<<<
end
end
end
classdef boreholes
properties
H;D;r_b;x;y
end
methods
function obj = boreholes (H ,D ,r_b ,x ,y)
obj.H = H;obj.D = D;obj.r_b = r_b;obj.x = x;obj.y = y;
end
end
end
How can I solve this?

回答(1 个)

dpb
dpb 2020-11-21
Don't need to save in the function with that name, just the output variable name chosen for the return value in the function definition line has to be defined. You make the assignment in the code above that calls the function. But, it doesn't matter what the return variable is named in the function; it's just a dummy anyway so doesn't hurt to leave it as is.
boreSegments = boreholesegments(borefield, nSegments);
...
end
function boreSegments = boreholesegments(borefield, nSegments)
...
boreSegments = boreholes(H ,D,borefield(j).r_b,borefield(j).x,borefield(j).y);
  1 个评论
MRF
MRF 2020-11-21
编辑:MRF 2020-11-21
Thanks for replay. Sir i need to save all argument of ans into a vector or array. Like this :
Unfortunately, this line returns only one property:
boreSegments = boreholes(H ,D,borefield(j).r_b,borefield(j).x,borefield(j).y);
I used this:
...
boreSegments(i,1) = boreholes...
(H ,D,borefield(j).r_b,borefield(j).x,borefield(j).y); % <<<<<<<<<<<<<<
end
boreSegments(:,j) = boreSegments;
...
But :(
Could you help me, please?
Thank you in advance!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Class Introspection and Metadata 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by