How can I create a 1*1struct data, which has two fields?

I want to create a mat file, which contains 1*1 struct data with two fields. One is "label" and another is "train". Label containst a 320*320 image and train contains "320*320" random lines.
A sample is given below .

12 comentarios

This is 256*256. I want to create similar one, which is 320*320.
So, what's the issue, precisely?
S.label=yourimagearray;
S.train=rand(320);
save 'YourNewMatFileName' S
For clear view, please download the file of the first comment. Then, load it and
figure,imshow(data.train)
I am trying to generate something exactly like that.
dpb
dpb el 9 de Mayo de 2022
What I gave you will let you do exactly that if the field variable train will contain an image array suitable for imshow
What you Q? said was you wanted a random variable there.
Still don't see the problem. What have you done to try to solve it and where did you have a problem?
Gulfam Saju
Gulfam Saju el 9 de Mayo de 2022
Editada: Gulfam Saju el 9 de Mayo de 2022
row = 320;
col = 320;
mask = zeros(row, col);
mask(:, 113:144) = 1;
idx_avail = 1:col;
idx_avail(113:144) = [];
N_avail = numel(idx_avail);
random_idx = idx_avail(randperm(N_avail,30));
mask(:,random_idx) = 1;
figure, imshow(mask);
I tried this. Your code just genrates random dots whole over the image. But I want something in vertical form. For the reference view the first comment's image (data.train).
dpb
dpb el 9 de Mayo de 2022
That's very inconvenient at the moment owing to other real work/data loaded in my workspace I don't want to mess with...attach the image as an image (use the image icon left of the paper clip). I've found saving fig as .jpg works nicely here...
Gulfam Saju
Gulfam Saju el 9 de Mayo de 2022
Editada: Jan el 9 de Mayo de 2022
data.train
dpb
dpb el 9 de Mayo de 2022
Then
  1. Select the number of coordinates in x direction
  2. Compute a spacing for those based on whatever is the underlying distribution desired -- looks something like inverse 1/x kind of thing, maybe.
  3. Given those positions, set the density of the speckles for each line
  4. Generate the positions to set -- nchoosek might be useful here as one way to generate the random permutation of vertical coordinates
Jan
Jan el 9 de Mayo de 2022
@Gulfam Saju: I've edited your comment such that the image is displayed as image directly. This is more convenient than posting a link.
Your image is huge: 3840x1940 pixels. It is hard to guess, what exactly do you want in your 320x320 image based on this example. Does the large white border matter? The description "train contains "320*320" random lines" is far to vague to be answered seriously.
yeah thanks. The white area doesn't matter.
dpb
dpb el 9 de Mayo de 2022
Yeah, @Jan, I presumed the 320 image was/is the black portion only and that the remainder is a fignewton of the method used to capture it...some of the MS tools are very bad in that regards of not having convenient ways to set an output format.
Jan
Jan el 9 de Mayo de 2022
@Gulfam Saju: Okay, I'vwe removed the white border for you also. It would be smart, if you do such work by your own. The less the readers have to do, the more time they have to provide a useful answer. So it is a good idea to provide the details such, that answering is as easy as possible.
The posted image has a structure and is not random. Look on the round artifacts in the corners. Does this matter?

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Productos

Versión

R2022a

Etiquetas

Preguntada:

el 9 de Mayo de 2022

Comentada:

Jan
el 9 de Mayo de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by