matrix dimension mismatch error

Hi, this is my code.
my data is known as matrix_data(1,512). I want to save every iteration of matrix_data in a new array(new_matrix_data) so that in new_matrix_data there will be (1,5120). However, there is error in my code 'matrix dimensions mismatch' in this line new_matrix_data(1,k:k+512) = matrix_data(1,:);
Anyone can help me?
new_matrix_data=zeros(1,5120);
l=1;
k=1;
while l~=2;
new_matrix_data(1,k:k+512) = matrix_data(1,:);
k=k+512;
save new_matrix_data 'new_matrix_data'
if k>=5120
new_data_matrix=zeros(1,5120);
k=1;
end
end

 採用された回答

Walter Roberson
Walter Roberson 2015 年 8 月 25 日

0 投票

k:k+512 is 513 elements. k:k+511 would be 512 elements.

5 件のコメント

mira
mira 2015 年 8 月 25 日
hi,
Thank you for the reply. However, I still got an error 'subscripted assignment dimension mismatch'. why is that so?
Walter Roberson
Walter Roberson 2015 年 8 月 25 日
Please show your corrected code and show size(matrix_data) at the time of the error. You can use
dbstop if error
and run and then when the error occurs you can see what size(matrix_data) is.
mira
mira 2015 年 8 月 25 日
It works. However, the data keep overwrites and only saved the last data.
Walter Roberson
Walter Roberson 2015 年 8 月 25 日
That is what is expected to happen when you continually save to the same file name.
Hint:
N = N + 1;
savefile_name = sprintf('new_matrix_data_%04d', N);
save(safefile_name, 'new_matrix_data');
mira
mira 2015 年 8 月 25 日
Actually I have tried the same concept as the above code but I will try by followed your code.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGet Started with MATLAB についてさらに検索

タグ

質問済み:

2015 年 8 月 25 日

コメント済み:

2015 年 8 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by