Info

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

Data Arrangment in a matrix

1 回表示 (過去 30 日間)
Dinouk Goonewardena
Dinouk Goonewardena 2020 年 4 月 9 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I want to insert NaN between (X Y BetaTol ) and the next (X Y BetaTol ) and so on, so it seperates with an NaN column, the code I have is below which does not respshape it properly
S={'X' 'Y' 'beta Tol'};
T= repmat(S,1,7); % to repeat character 7 times
T=reshape([T, nan(size(T,1),2,size(T,3))], 1, {}); % trying to insert NaN in between the characters

回答 (1 件)

Vinai Datta Thatiparthi
Vinai Datta Thatiparthi 2020 年 4 月 16 日
Hello Dinouk,
Well, firstly, you're using cell arrays in your code, but you mention matrix in the title. Since you're working with characters, I would continue to use cell arrays.
Your description of the problem is a little hazy, but if you want to insert NaN values in between the sequence, you could simply use a for loop and indexing to get the output -
for i=4:4:28 % This loop work for this specific case, generalize it for other cases
T = {T{1:i-1}, 'NaN', T{i:end}}; % Use indexing to add NaN value in every fourth index
end
This is a simpler approach of the many others to the problem that you have described. The output would be a [1x28] cell array.
Hope this helps!

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by