Matlab does wired stuff

1 次查看(过去 30 天)
bethel o
bethel o 2011-2-21
This is part of a function that is doing what i called wired. The vector 'dim_set' in this snippet should expanded on both side depending on the value of the scalar 'const'. I have no idea while the result is wired. Pls help!
% expand dim_set by 1 or a const on each side
dim_set=[67.5:100.5];
const=20;
dim_set %befor
dim_set=floor(dim_set);
if(dim_set(1)>1)
dim_set=[dim_set(1)-const:dim_set(1),dim_set];
end
dim_set=[dim_set,dim_set(end):dim_set(end)+const];
% See befoer and after values of dim_set to see this
dim_set %after
  6 个评论
bethel o
bethel o 2011-2-21
@Andreas Goser. i meant weird. I have been coding for stegers algorithm constantly for one week now, so am tired. And by the way is it 'ot weird' or 'or weird'?. lol there
Andreas Goser
Andreas Goser 2011-2-21
I noticed that :-) - can't edit the comments

请先登录,再进行评论。

采纳的回答

Paulo Silva
Paulo Silva 2011-2-21
dim_set=67.5:1:100.5
const=20;
dim_set %before
dim_set=floor(dim_set); %have no clue what's the purpose of this line
dim_set=[dim_set(1)-const:dim_set(1)-1 dim_set]; %expand left
dim_set=[dim_set dim_set(end)+1:dim_set(end)+const]; %expand right
% See before and after values of dim_set to see this
dim_set %after
  5 个评论
bethel o
bethel o 2011-2-21
yep cheers that one is corrected. but the issue remains.
Paulo Silva
Paulo Silva 2011-2-21
You were correct, now that I know what your function does I came to the conclusion that the borders are irrelevant but there's no need to waste a little more memory with duplicated values.

请先登录,再进行评论。

更多回答(1 个)

bethel o
bethel o 2011-2-21
function tf=intersect_l(dim_set,memb)
% expand dim_set by 1 or a const on each side
%dim_set=[67.5:100.5];
const=20;
dim_set %befor
dim_set=floor(dim_set);
if(dim_set(1)>1)
dim_set=[dim_set(1)-const:dim_set(1),dim_set];
end
dim_set=[dim_set,dim_set(end):dim_set(end)+const];
dim_set %after
if(intersect(dim_set,memb))
tf=1;
else
tf=0;
end
end
  9 个评论
bethel o
bethel o 2011-2-21
Thanks a lot Paulo. I have also tried it and it works, outside of its parent function (because its a sub function). I have no idea why it dosn't work for certain values of 'const' when ran through the parent function but works for all values of 'const' when ran as a function on its own.
I will have a sleep and come back to it.
Thanks alot for your assistance.
Bethel
bethel o
bethel o 2011-2-21
Hey Paulo, I did not realize that in programing if I have something like
IF(i && j), j will not be checked if i =false . this was simply the problem I was having. I was checking the output of j and only saw it some times (i and j are functions that returns boolean in my program). I did not know that the reason I was not seeing j sometimes was because sometimes i =false.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by