how to write this problem

hello everyone and thanks for previous answers. I have the code below
j=[1 2 3];
p=[1 2 1;
2 3 1;
3 1 2;
1 1 2];
now I need to code this:
c(1,3)=p(1,3);
c(2,3)=p(1,3)+p(2,3);
c(3,3)=p(1,3)+p(2,3)+p(3,3);
c(4,3)=p(1,3)+p(2,3)+p(3,3)+p(4,3);

2 件のコメント

dpb
dpb 2015 年 1 月 6 日
What's the issue? The above looks like perfectly valid Matlab code other than you could write it more succinctly.
HINT:
If that's the actual question, what is the name for the result of adding terms? Look for that in the help. The command
lookfor _keyword_
is very useful utility to learn in this regard as learning Matlab as is the simple
help
and then look at the areas that seem like might be related to your question.
And, of course, the "Getting Started" tutorial stuff shows examples of basic array manipulation.
alexaa1989
alexaa1989 2015 年 1 月 6 日
I need to code it with a FOR loop or a counter Im not sure

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

回答 (1 件)

Image Analyst
Image Analyst 2015 年 1 月 6 日

0 投票

Is this homework? Sounds like it. So I'll give you a hint: look up the "cumsum()" function if you want to do that code in 1 or 2 lines.

3 件のコメント

alexaa1989
alexaa1989 2015 年 1 月 6 日
its part of a genetic algorithm for permutation flow shop and Im a grad student its part of an article im working on not a homework
Image Analyst
Image Analyst 2015 年 1 月 6 日
Try this:
j=[1 2 3]; % Apparently ignored.
p=[1 2 1;
2 3 1;
3 1 2;
1 1 2];
% Now I need to code this:
% First method: alexaa's way
c(1,3)=p(1,3);
c(2,3)=p(1,3)+p(2,3);
c(3,3)=p(1,3)+p(2,3)+p(3,3);
c(4,3)=p(1,3)+p(2,3)+p(3,3)+p(4,3);
c % Print to command window.
% Alternative way
d = zeros(size(c));
d(:,3) = cumsum(p(:, 3))
alexaa1989
alexaa1989 2015 年 1 月 7 日
thanks ALOT

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

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

タグ

質問済み:

2015 年 1 月 6 日

コメント済み:

2015 年 1 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by