What is the problem in simple matrix operation.?
이전 댓글 표시
clear all;clc
names = {'A'; 'B'; 'C'; 'D'};
marks = [27; 48; 84; 22];
in_st = {names marks};
in_st = [names num2cell(marks)];
function [op_st1,op_st2] = print_Data(in_st)
in_st = in_st;
[~,idx] = sort(in_st(:,1));
op_st1 = in_st(idx,:)
[~,idx] = sort(in_st(:,2),'descend');
op_st2 = in_st(idx,:)
I want op_st1 in ascending order, and op_st2 in descending order. It works well upto half program, what is the problem in remaining..?
댓글 수: 2
Azzi Abdelmalek
2014년 11월 23일
편집: Azzi Abdelmalek
2014년 11월 23일
What is the error message?
Nimisha
2014년 11월 23일
채택된 답변
추가 답변 (1개)
Azzi Abdelmalek
2014년 11월 23일
편집: Azzi Abdelmalek
2014년 11월 23일
Use curly brackets { }
[~,idx] = sort(in_st{:,2},'descend')
댓글 수: 3
Guillaume
2014년 11월 23일
Huh? That's not going to work. It'll just convert the 2nd column of the cell array into a comma separated list that sort won't know what to do with.
Nimisha
2014년 11월 23일
Azzi Abdelmalek
2014년 11월 23일
[~,idx] = sort([in_st{:,2}],'descend')
카테고리
도움말 센터 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!