seven_swodniw
seven_swodniw

Reputation: 881

Problems which matlab is good for

Let me ask whether using Matlab for my particular problem is nonsense or some people do the similar.

I have an initial sequence S(1), where each term is a 2D point. I create a new sequence S(2) by inserting a new term point p between each consecutive 2 term points p(i) and p(i+1). Where p is a function f of 4 term points of nearest indices on S(2). Namely,

p= f( p(i-1),p(i),p(i+1),p(i+2) )

And the function f is written in a C like style but not in the pure style of matrix language. In the same way , I repeat generating the new longer sequence S(i+1) up to S(m).

The above may be vague for you, but please give some advice. I do not ask whether Matlab is the best choice for the problem , but whether no expert will use Matlab for such a problem or some will.

Thank you in advance.

Upvotes: 2

Views: 156

Answers (2)

cyborg
cyborg

Reputation: 10139

It heavily depends on f. If f could be coded efficiently in Matlab or you are willing to spend the time to MEX it (Matlab C extension), then Matlab will perform efficiently.

The code could be vectorized like this:

f = @(x) mean(x,3);
m=3;
S{1}=[1,2,3;4,5,6];
for i=2:m
    S{i} = cat(3,...
        [[0;0] S{i-1}(:,1:end-2)],...
        S{i-1}(:,1:end-1),...
        S{i-1}(:,2:end),...
        [S{i-1}(:,3:end) [0;0]]);
    S{i} = [f(S{i}) [0;0]];
    S{i} = cat(3,S{i-1},S{i});
    S{i} = permute(S{i},[1 3 2]);
    S{i} = S{i}(:,:);
    S{i}(:,end)=[];
end

Upvotes: 2

silvado
silvado

Reputation: 18137

Yes, Matlab seems to be suitable for such a task. For the data structure of your list of sequences, consider using cell arrays. You could have S as a cell array, and S{1} would correspond to your S(1), and could again be a cell array of points, or a usual matrix if points are just pairs or triples of numbers.

As an alternative, Python in my opinion is particulary strong when it comes to all kind of sequences.

Upvotes: 1

Related Questions