フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to convert a vector into a matrix using reshape ,but what should be the size that should be specified?

1 回表示 (過去 30 日間)
Anushka
Anushka 2015 年 7 月 10 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I have converted a matrix A into a vector v and performed certain operations on the vector v and obtain a new vector G which have less number of elements compared to vector v.Now I want to convert this vector g into a matrix?But I dont know what must be the size that should be specified while using reshape.

回答 (1 件)

James Tursa
James Tursa 2015 年 7 月 10 日
If it has fewer elements than originally, you can't directly reshape it into the same size original matrix. You could pad with 0's or NaN's if that works for your downstream processing. E.g.,
n = numel(v); % Number of original elements
G(end+1:n) = NaN; % Pad with NaN's
B = reshape(G,size(A)); % Reshape back to original size
If that doesn't work for you, then you will need to give us more details about what you will be doing with the reshaped G vector downstream in your code. Then we can offer suggestions.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by