Hi everybody,
I have code given below, num is a 1500x3 sized matrix and it has class labels in its third column and number of the classes labels are change according to the input value . I want to keep each line in the class matrix in certain places by class number like Class 1 will be held between 1 and 400 lines,Class 2 will be held between 401 and 790 lines etc. but code gicen below always writes the values same lines
clc; clear all;
[num,txt,raw] = xlsread('data-1.xlsx');
k = input ('Enter a k value:');
for d =1:k ;
lclass = length(num(num(:,3)==d,1:2));
a(d+1) = lclass;
class(:,1:2) = [num(num(:,3)==d,1:2)];
end

 채택된 답변

David Hill
David Hill 2020년 3월 8일

0 개 추천

class=[];
for d =1:k ;
class= [class,num(num(:,3)==d,1:2)];
end

댓글 수: 4

David Hill
David Hill 2020년 3월 8일
class=[];
for d =1:k ;
class= [class;num(num(:,3)==d,1:2)];%needs to be ;
end
Ararat Cetinkaya
Ararat Cetinkaya 2020년 3월 8일
with using this expression 'class=[];', did we assignme a matrix to class variable ?
David Hill
David Hill 2020년 3월 8일
Yes, an empty matrix
Ararat Cetinkaya
Ararat Cetinkaya 2020년 3월 8일
it helped me a lot thanks for your help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

태그

Community Treasure Hunt

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

Start Hunting!

Translated by