Resizing an array - removing elements
11 次查看(过去 30 天)
显示 更早的评论
I have an array of data, in this case 61 rows long. I need to reshape this into 3s - LSB1 = reshape(LSB,3,[]); but as 61 isn't divisible by 3, it wont work.
I want to be able to remove the last value of from the vector in this case, via an if statement (sometimes maybe to remove the last 2 values if there were 62 rows instead) i.e. an if statement to check divisibility by 3 and then to remove the correct number of elements from the end of the array.
Thank you
1 个评论
Ahmad Kanzu Syauqi Firdaus
2018-9-3
you can also use imresize, especially when you want to decrease array dimension without changing array content generally. example:
X=rand(105,1); M=61; Xnew=imresize(X,[M,1]);
采纳的回答
Star Strider
2016-1-6
If you only want 60 rows in your array, just redefine a new array to have 60 rows:
LSB = rand(61,1); % Create Data
LSBnew = LSB(1:60,:);
LSB1 = reshape(LSBnew, [], 3);
6 个评论
Star Strider
2016-1-8
My pleasure!
Since you are starting with a column vector, reverse the last two arguments in reshape and transpose the result:
x = [1:9]';
y = reshape(x, 3, [])';
This should do what you want.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!