What is the problem in these code?
信息
此问题已关闭。 请重新打开它进行编辑或回答。
显示 更早的评论
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 个评论
回答(2 个)
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 个评论
Selin Soguksu
2012-12-19
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.
Selin Soguksu
2012-12-19
0 个投票
3 个评论
Jürgen
2012-12-19
no problem
José-Luis
2012-12-19
And the mistake was?
Selin Soguksu
2012-12-20
此问题已关闭。
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!