how to create different matrices?
7 次查看(过去 30 天)
显示 更早的评论
i have 30,000 rand value that i want to separate 400 to 400...then i wanna plot them but the x axis should start at 0 not 400 or 800 or...any help please?
采纳的回答
Jonas
2022-12-7
you could split them into multiple 400x1 vectors by this
data=rand(30000,1);
data=reshape(data,400,1,[]);
size(data)
you can then get each vector using indexing data(:,:,idx)
for idx=1%:75 % commented out to avoid to much plotting here
plot(0:399,data(:,:,idx));
% saveas(gcf,[num2str(idx),'.jpg']);
end
11 个评论
DGM
2022-12-7
编辑:DGM
2022-12-7
You can do that, but you'll have to figure out how you want the image shaped, whether you want the ticks plotted, etc.
npoints = 30000; % or some multiple of 400
blocklen = 400;
startidx = 0;
% generate x,y
x = startidx:startidx+npoints-1;
y = rand(npoints,1);
% reshape
x = reshape(x,blocklen,[]);
y = reshape(y,blocklen,[]);
% plot and capture
nframes = size(x,2);
allframes = cell(nframes,1);
for k = 1:nframes
plot(x(:,k),y(:,k))
allframes{k} = frame2im(getframe(gcf));
end
This will save all the frames in a cell array. Alternatively, you can write them using imwrite().
Note that as images, the details of the start/end indices is moot, since the ticks aren't going to show that detail well enough for anyone to tell. You could always try to enforce the exact axis limits, but it's still not going to help much.
% place this in the loop between plotting and capture
xlim(x([1 end],k))
ylim([0 1])
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!