Error ??? Subscript indices must either be real positive integers or logicals.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I created a script to read a vector from the Excel file.
Script:
V = xlsread('C:\ad\fMRI\vbm_cat\subjectsdata\vbmcatsub.xls');
variables = ('Age FPQ CPS RUM MAG HEL STAI_A STAI_B SEX')
========================================
Then I get a vector V with the size of 36*9,
I need to get the values of each variable. so I type the commands then I get the following error message
>> V(i,1) ??? Subscript indices must either be real positive integers or logicals.
Why is this? How to fix it?
Thanks.
0 Commenti
Risposte (5)
Shane
il 19 Set 2012
First off, depending upon what kind of data you have in your excel file, you might need to use two ouputs in the xlsread function as shown: [numericValues textValues]=xlsread(‘FILE’) See help xlsread for why this is.
Secondly, the error message you have shown is because you have not defined the variable “i” to be an integer. In order to determine the first variable in the matrix V you would have to type V(1,1). If you simply want to display all of the variables you could use a for loop:
For i = 1:36
For j = 1:9
V(i,j)
End
End
Long story short, you just need to define your variables before trying to use them as a callout.
I hope this helped :)
2 Commenti
Shane
il 19 Set 2012
If you want a single variable for ALL participants, use
desiredVariable = V(:,columnNumber)
If you want a single variable for participants 10 through 15 for instance, use
desiredVariable = V(10:15,columnNumber)
Andrei Bobrov
il 19 Set 2012
Modificato: Andrei Bobrov
il 19 Set 2012
use struct - array:
out = cell2struct(num2cell(V),regexp(variables,'\w*','match'),2);
or
out = cell2struct(num2cell(V,1),regexp(variables,'\w*','match'),2);
or
data = [regexp(variables,'\w*','match');num2cell(V,1)];
out = struct(data{:});
or
data = [regexp(variables,'\w*','match');num2cell(num2cell(V),1)];
out = struct(data{:});
0 Commenti
Matt Tearle
il 19 Set 2012
Modificato: Matt Tearle
il 19 Set 2012
To get the fourth variable:
RUM = V(:,4);
The : as the first index represents all rows.
Given your description of the data, you might also want to consider using a dataset array (requires Statistics Toolbox).
V = dataset('XLSFile','filename.xls');
Then you can refer to variables by name: V.RUM (assuming there is a header row in the Excel file that can be used to define the variable names).
1 Commento
Shane
il 19 Set 2012
The statistics toolbox is a powerful tool but if you are just going to be doing basic data analyses I would suggest sticking with the standard annotation as shown by
RUM = V(:,4);
vanaja m
il 10 Mar 2014
i too got the same problem while performing speaker recognition using vq method.......here is the code and the error is ??? Subscript indices must either be real positive integers or logicals.
Error in ==> vqlbg at 30 c(:, i) = mean(d(:, (find(ind == j))), 2); code: clc clear all; close all; code=train('C:\Users\welcome\Desktop\project\matlab\train\',8); test('C:\Users\welcome\Desktop\project\matlab\test\',8,code); train.m: function code = train(traindir, n)
k = 16;
for i = 1:n
file = sprintf('%ss%d.wav', traindir, i);
disp(file);
[s, fs] = wavread(file);
size(s)
v = melfcc(s, fs); % Compute MFCC's
code{i} = vqlbg(v, k); % Train VQ codebook
end
test.m
function test(testdir, n, code)
for l = 1:length(code) % each trained codebook, compute distortion
% code{l}(end:numel(v))=0;
d = disteu(v, code{l});
dist = sum(min(d,[],2))/size(d,l);
if dist1< distmin
distmin = dist;
k1 = l;
end
end
msg = sprintf('Speaker %d matches with speaker %d', k, k1);
disp(msg);
melfcc.m:
function r = melfcc(s, fs1)
m=160;
n=256;
frames=blockFrames(s,fs1,m,n);
t=n/2;
tmax=length(s)/fs1;
m=melfb(n,16,fs1)
n2=1+floor(n/2)
length(m);
length(frames)
disp(frames)
% z=m*abs(frames(1:n2,:)).^2;
r=dct(log(abs(frames)));
end
blockFrames.m:
function M3 = blockFrames(s, fs, m, n)
l = length(s);
nbFrame = floor((l - n)/m) + 1;
for i = 1:n
for j = 1:nbFrame
M(i, j) = s(((j - 1) * m) + i);
end
end
h = hamming(n);
M2 = diag(h) * M;
for i = 1:nbFrame
M3(:, i) = fft(M2(:, i));
end
end
size(code{1})
melfb.m:
function m = melfb(p, n, fs)
f0 = 700 / fs;
fn2 = floor(n/2);
lr = log(1 + 0.5/f0) / (p+1);
bl = n * (f0 * (exp([0 1 p p+1] * lr) - 1));
b1 = floor(bl(1)) + 1;
b2 = ceil(bl(2));
b3 = floor(bl(3));
b4 = min(fn2, ceil(bl(4))) - 1;
pf = log(1 + (b1:b4)/n/f0) / lr;
fp = floor(pf);
pm = pf - fp;
r = [fp(b2:b4) 1+fp(1:b3)];
c = [b2:b4 1:b3] + 1;
v = 2 * [1-pm(b2:b4) pm(1:b3)];
m = sparse(r, c, v, p, 1+fn2);
end
disteu.m:
function d = disteu(x, y)
[M, N] = size(x);
[M2, P] = size(y);
if (M ~= M2) error('Matrix dimensions do not match.') end
d = zeros(N, P);
if (N < P) copies = zeros(1,P); for n = 1:N d(n,:) = sum((x(:, n+copies) - y) .^2, 1); end else copies = zeros(1,N); for p = 1:P d(:,p) = sum((x - y(:, p+copies)) .^2, 1)'; end end
d = d.^0.5; end vqlbg.m: function c =vqlbg(d, k) % VQLBG Vector quantization using the Linde-Buzo-Gray algorithm % % Inputs: % d contains training data vectors (one per column) % k is number of centroids required % % Outputs: % c contains the result VQ codebook (k columns, one for each % centroids)
%Hints
%Cluster Vectors (Nearest-Neighbor Search): c=mean(d,2);
%The nearest-neighbor search step is: given a current codebook c, assign each training vector in d with a closest codeword. To do that, one needs to compute the pair-wise distances between each vectors in d to each vectors (codeword) in c. This can be done with the supplied function disteu: z = disteu(d, c);
%Now z(i, j) would be the distance between the training vector d(:, i) and the codeword c(:, j). Next step, for each training vector, find the closest codeword. For this, use the Matlab function min:
[m, ind] = min(z, [], 2);
%The result index vector ind contains the associated cluster number for each training vector. So to access to all the training vectors that belong to the cluster number j (those vectors that are closest to the codeword c(:, j)), one can use:
d(:, find(ind == j));
%Find Centroids
%The centroid of all vectors in a particular cluster is found by the Matlab function mean. For example, after the Nearest-Neighbor Search step above, the new centroids of the clusters number j can be updated as follows: c(:, i) = mean(d(:, (find(ind == j))), 2); % c(:, j) = mean(d(:, b, 2)); end plssssssssssssshelp urgent
0 Commenti
Vedere anche
Categorie
Scopri di più su Statistics and Machine Learning Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!