Append multiple values in one variable

9 ビュー (過去 30 日間)
Sara Ejaz
Sara Ejaz 2023 年 3 月 18 日
コメント済み: the cyclist 2023 年 3 月 19 日
hello,
i read an image using
img=imread('612.jpg')
then convert this 512x512 matrix into one column
using
newimg=img(:);
this give me a single column value 786432x1
know i want to insert new picture value started from 786433 and proceed next..
This experiment apply for 500 pictures..

回答 (1 件)

the cyclist
the cyclist 2023 年 3 月 18 日
Assuming the image are all the same size, 512x512, then I would "stack" them in the 3rd dimension, then convert everything to a vector at once. You don't mention how the variables are stored, the naming convention, etc, but it would go something like this
% Number of images
N = 500;
% Preallocate the 3d array
img_array = zeros(512,512,N);
% Loop to fill each "slice" in 3d
for ni = 1:N
img_array(:,:,ni) = ... % Here is where you need to figure out how to access each image
end
% Convert the whole thing to a vector. (This will be in the same order as if you had stacked them individual.)
img_vector = img_array(:);
  7 件のコメント
Sara Ejaz
Sara Ejaz 2023 年 3 月 19 日
i store image data into excel file with the size of 786432x1
first file name is 1.csv second file is save as 2.csv upto 500 hundred files each file contain 786432x1 record
know a want to merge all these files in such a way that if first file end an 786432 row then second file record start at 786433 to 1572864
3rd image recored start at 1572865 and upto soo on
all 500 picture are in store in single file with one column
i want this..
the cyclist
the cyclist 2023 年 3 月 19 日
% The number of files you have
N = 500;
% Length of each file
L = 786432;
% Preallocate the memory for the large file.
out = zeros(L,N);
% Loop over the input files, and store them
for ni = 1:N
filename = sprintf("%d.csv",ni); % This read 1.csv, 2.csv, 3.csv, etc, up to N.csv
out(:,ni) = readmatrix(filename);
end
% Write output as one long vector
writematrix(out(:),"long.csv");

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

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by