Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

What is the problem in these code?

조회 수: 1 (최근 30일)
Selin Soguksu
Selin Soguksu 2012년 12월 19일
마감: MATLAB Answer Bot 2021년 8월 20일
Hello friends, I have a code like this:
for x=1:50
Nrows=size(orj_matr,1)
new_matr=randperm(Nrows)
new_matr=new_matr(1:50)
a(:,:,x)=orj_matr(new_matr,:)
end
When I wrote this codes to MATLAB, I have 50 different (50 rows-10 columns) matrices. Like this:
a(:,:,1) , a(:,:,2), a(:,:3), …………a(:,:,50)
And I want to calculate f1 and f2 for these 50 different matrices. When I wrote like this there was an error saying “Indexing must appear last in an index expression”.
f1=sum(a(:,:,x) (:,1:2:end),2);
f2=sum(a(:,:,x) (:,2:2:end),2);
What is the mistake in these codes? Please help me...
  댓글 수: 1
Jan
Jan 2012년 12월 19일
편집: Jan 2012년 12월 19일
It would be useful if you explain, what the the expression "a(:,:,x) (:,1:2:end)" should do. As long as it is no valid Matlab syntax, a suggestion for improvement requires guessing what you want to achieve. And an answer based on guesses can be worse than no answer.

답변 (2개)

Jürgen
Jürgen 2012년 12월 19일
편집: Jürgen 2012년 12월 19일
Hi,
sum(a(:,:,x) (:,1:2:end),2); is not correct , I think What do you want to do there? '(:,1:2:end)' is referring to the index and it put at the right place regards,J
  댓글 수: 3
José-Luis
José-Luis 2012년 12월 19일
I would recommend you read up on indexing.
a(:,:,x) (:,1:2:end)
is not a valid expression. I am guessing that what you want is something along the lines
squeeze(sum(a(:,1:2:end,:),2))
Also, please edit your code to make it more readable. That might attract more answers.
Jürgen
Jürgen 2012년 12월 19일
편집: Jan 2012년 12월 19일
to sum all even columns:sum(A(:,2:2:end)) for odd columns: sum(A(:,1:2:end))

Selin Soguksu
Selin Soguksu 2012년 12월 19일
Thanks all of you for the answers and comments. I saw my mistake and correct my codes. Now it works good. I know my codes are not clear enough, because I am very new with MATLAB. And also sometimes I can't tell you what I want because of my poor English.
  댓글 수: 3
José-Luis
José-Luis 2012년 12월 19일
And the mistake was?
Selin Soguksu
Selin Soguksu 2012년 12월 20일
When I assign a(:,:,x) to a new variable, and use this variable to the entire of the code, there was no problem.

이 질문은 마감되었습니다.

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by