How to store words and numbers table in an array

can anyone help me to create an empty array to store a 11 x 3 string array.
I am rating a loop to store each value for every image. i have to loop i just can't create a suitable array to store the words and numbers. This is what each image gives out:
"Sky" "268032" "786432"
"Building" "0" "0"
"Pole" "131" "786432"
"Road" "734" "786432"
"Pavement" "7610" "786432"
"Tree" "7450" "786432"
"SignSymbol" "7082" "786432"
"Fence" "5490" "786432"
"Car" "6912" "786432"
"Pedestrian" "3669" "786432"
"Bicyclist" "9836" "786432"
Thanks.

12 Comments

the code i have been using to try this is:
labels = categorical.empty(1,0);
A = table2array(Q)
labels(1,1) = A;
i am getting an error stating
"Error using categorical/parenAssign (line 79)
Right hand side of an assignment to a
categorical array must be a categorical or text
representing a category name."
Why are you using categorical variables and tables when you've requested to make a string array in the question? Perhaps the goal is evolving in which case it would be a good idea to resolidify the goal.
I basically want to create an array to store the value from the table : the label, pixel count etc that is shown above. this will be completed for the total number of images so run through a loop that has been implemented for n = 1:total_images. Each image I want it to save the 11 x 3 values from the table in one array.
filenames = dir(fullfile(image_folder, '*.jpg'));
total_images = numel(filenames);
labels = strings(total_images, 0);
for n = 1:total_images
f = fullfile(image_folder, filenames(n).name);
our_images = imread(f);
C = semanticseg(our_images, net);
B = labeloverlay(our_images,C,'Colormap',cmap,'Transparency',0.4);
label_bim = blockedImage(B, 'BlockSize', [512 512]);
lbimds = blockedImageDatastore(label_bim);
Q = countEachLabel(lbimds, ...
"Classes", ["Sky", "Building", "Pole", "Road", "Pavement", "Tree", "SignSymbol", "Fence", "Car", "Pedestrian", "Bicyclist"],...
"PixelLabelIDs", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
A = table2array(Q);
labels(n,1) = A;
end
Do either of the answers below satisfy that request?
Why not just keep the table rather than storing the values in an array?
Hi, unfortunately not. I need to store each table in the array. I have 1495 photos to run through and each photo will return a table with they values. The pixel values in the table will then be used inside an ANN to predict the photo. This is why I need to store each table in the same array under each other so I can easily use this by copying and pasting onto excel and creating a data set with a CSV file. I have the loop to give the value for each image the only problem is saving this onto the same array each time so I don’t need to run through 1495 images and copy and paste each as that will take too long. Thanks , Ben
But the question asks " can anyone help me to create an empty array to store a 11 x 3 string array"
The comment above is a completely different goal.
" I need to store each table in the same array under each other"
If the tables have the same headers you could vertically concatenate the tables. Otherwise you can store them in a Cell array.
Thanks, how do you actually do that? I’m just new to using matlab this year.
c = cell(n,m); for nxm empty cell array
then store the tables
c{i,j}= T where T is a table
I appreciate your help Adam thanks, I’ll try this tomorrow morning !
what is this vairable 'm' you are using or 'j' and 'i'? im guessing the 'n' is n i have already declared but none of these other values have been declared.
They are just indices.
n and m are defined in my comment (".... for nxm empty cell array).
i and j are just indices. c(i,j) is the i_th row and the j_th column.

Sign in to comment.

Answers (1)

Why not set up a struct?
s = struct('a',{},'b',{},'c',{});%label the fields to whatever you want
for k=1:11
s(k).a=%'Building' from picture
s(k).b=%268032
s(k).c=%786432
end

Categories

Asked:

on 7 Apr 2021

Commented:

on 8 Apr 2021

Community Treasure Hunt

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

Start Hunting!