在 Scilab 中使用 csvRead 后如何逐行扫描矩阵?
How to scan matrix by row after using csvRead in Scilab?
data=csvRead("C:\Users\USER\Desktop\Iris.csv",",","%f");
是我在 Scilab 中用来读取包含以下内容的文件的代码:
5.1,3.5,1.4,0.2,山鸢尾
4.9,3.0,1.4,0.2,山鸢尾
4.7,3.2,1.3,0.2,山鸢尾
4.6,3.1,1.5,0.2,山鸢尾
5.0,3.6,1.4,0.2,山鸢尾
7.0,3.2,4.7,1.4,杂色鸢尾
等等...
now what I want to do is to manipulate the data by row and apply it to a clustering algorithm.
For example I want to use each of the values in row one to calculate their euclidian distance between the centroids.
How would I know the index of each value and how do use it in computations?
I want to manipulate the data just like this code in Java.
for(i=0; i < popnSize; i++){
for(j=0; j < dim; j++){
System.out.println("["+i+"]" + arrpop[i][j]+"\t");
}
How would you translate that in Scilab after reading the matrix using csvRead?
如下:
for i=1:popnSize
for j=1:dim
printf("[%d]%g\t",i, arrpop(i,j))
end
end
之后
--> data=csvRead("C:\Users\USER\Desktop\Iris.csv",",","%f");
计算到质心的距离可以通过将数据矩阵在行方向居中然后计算每行的范数来完成:
--> dist = sqrt(sum(center(data(:,1:4),1).^2,2))
dist =
0.6407461
0.7168604
0.8566732
0.8065702
0.7074995
3.4274221
data=csvRead("C:\Users\USER\Desktop\Iris.csv",",","%f");
是我在 Scilab 中用来读取包含以下内容的文件的代码:
5.1,3.5,1.4,0.2,山鸢尾
4.9,3.0,1.4,0.2,山鸢尾
4.7,3.2,1.3,0.2,山鸢尾
4.6,3.1,1.5,0.2,山鸢尾
5.0,3.6,1.4,0.2,山鸢尾
7.0,3.2,4.7,1.4,杂色鸢尾
等等...
now what I want to do is to manipulate the data by row and apply it to a clustering algorithm. For example I want to use each of the values in row one to calculate their euclidian distance between the centroids.
How would I know the index of each value and how do use it in computations?
I want to manipulate the data just like this code in Java.
for(i=0; i < popnSize; i++){
for(j=0; j < dim; j++){
System.out.println("["+i+"]" + arrpop[i][j]+"\t");
}
How would you translate that in Scilab after reading the matrix using csvRead?
如下:
for i=1:popnSize
for j=1:dim
printf("[%d]%g\t",i, arrpop(i,j))
end
end
--> data=csvRead("C:\Users\USER\Desktop\Iris.csv",",","%f");
计算到质心的距离可以通过将数据矩阵在行方向居中然后计算每行的范数来完成:
--> dist = sqrt(sum(center(data(:,1:4),1).^2,2))
dist =
0.6407461
0.7168604
0.8566732
0.8065702
0.7074995
3.4274221