Unable to perform assignment because the indices on the left side are not compatible with the size of the right side

1 回表示 (過去 30 日間)
for jk=1:1:length(pliki)
tak=0;
p0=pliki(jk);
p00=char(p0);
pl0=(strcat(sciezka,pliki(jk)));
tab_plikow(jk)=pl0;
plik0=char(pl0);
Thats the part of old code i need to change but don't know how. tab_plikow has:"appears to change size on every loop iteration, consider preallocating". Was trying with zeroes for tab_plikow but it doesn't seems to work or I'm doing something wrong. Any help would be appreciated, thanks.
  6 件のコメント
Marco Soto
Marco Soto 2021 年 5 月 18 日
I had a problem just like me, it was solved: removing the global variables.

サインインしてコメントする。

回答 (2 件)

Walter Roberson
Walter Roberson 2018 年 11 月 20 日
編集済み: Walter Roberson 2021 年 5 月 18 日
unless sciezka is empty then the result of the strcat will be a character vector of at least two char. You try to store the two char into a single numeric location .
Use cell arrays or string objects .
  7 件のコメント
Piotr Matysiak
Piotr Matysiak 2018 年 12 月 4 日
Actually I am using third output in code.. Look here
[y1,fs,b]=audioread(plik0);
lk1=size(y1);lk=lk1(2);
plik1=sprintf('%s',sciezka_start,'\Temp\temp1.wav');
audiowrite(y1,plik1,b);
if fs~=8000 | lk~=1 | b~=16
konw;
k_tekst0=sprintf('%s','Parametry pliku ',plik0,' :');
k_tekst1=sprintf('%s','Częstotliwość próbkowania: ',num2str(fs));
k_tekst2=sprintf('%s','Ilość bitów: ',num2str(b));
k_tekst3=sprintf('%s','Liczba kanałów: ',num2str(lk));
So how can i use audioinfo() and b output?
And second question, why tab_plikow is giving me this when i run program
tab_plikow =
1×10 cell array
Columns 1 through 5
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
Columns 6 through 10
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
Walter Roberson
Walter Roberson 2018 年 12 月 4 日
The third parameter to audiowrite() is the the sample rate, fs, not the bits per sample.
info = audioinfo(plik0);
if isfield(info, 'BitsPerSample')
b = info.BitsPerSample;
else
b = nan;
end
Does your code still have
tab_plikow = zeros(length(pliki),1);
If it does then what does kown do ? Is it possibly a script that overwrites tab_plikow ?

サインインしてコメントする。


Image Analyst
Image Analyst 2018 年 11 月 20 日
Try this
tab_plikow = zeros(1, length(pliki));

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by