How to load a folder according to a vector into matlab?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I have a matrix called perStimAtten (2x40):
perStimAtten =
-1 -1 -1 -1 -1 -2 -2 -2 -2 -2 -1 -2 -1 -1 -2 -2 -2 -1 -1 -2 -2 -1 -2 -1 -1 -1 -2 -1 -2 -2 -2 -1 -1 -1 -1 -2 -2 -2 -1 -2
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
This matrix was build by matlab to create randomly sound stimulus, which stimulates neurons in mice. The pictures of the neurons captured by each stimulus refers to the array of the first row. I used this command:
[yy ii]=sortrows(perStimAtten');
to sort the rows into columns, and I got vector yy (40x2) which shows me that rows 1-20 of vector ii (40x1) were stimulated by stimulus number 2, and rows 21-40 were stimulated by stimulus number 1. Vector ii sorts the files (containing the pictures) in rows 1-40 so I can know which picture is connected to which stimulus.
Now I need to load to matlab the pictures taken when stimulus 1 was heard, and then when stimulus 2 was heard.
How do I draw the correct pictures according to vector ii?
Thank you! Sigal.
For convenience:
yy:
-2 0
-2 0
-2 0
-2 0
-2 0
-2 0
-2 0
-2 0
-2 0
-2 0
-2 0
-2 0
-2 0
-2 0
-2 0
-2 0
-2 0
-2 0
-2 0
-2 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
-1 0
ii:
6
7
8
9
10
12
15
16
17
20
21
23
27
29
30
31
36
37
38
40
1
2
3
4
5
11
13
14
18
19
22
24
25
26
28
32
33
34
35
39
5 commentaires
Jan
le 27 Août 2017
@Sigal: Did you see my questions for clarifications? I would like to help you, but as long as I do not understand these points, I can't.
The error message you get is clear: You cannot use load to import a tif file. Use imread instead.
It is not meaningful to "load" all the data only. Explain, what should happen with the imported value. Then it will be much easier to help you to implement this.
Réponses (1)
Guillaume
le 27 Août 2017
Modifié(e) : Guillaume
le 27 Août 2017
As per Jan's questions, it's really not clear what exactly you want to do. The following will load all the images in a cell array, as per (your badly named ii) order vector:
[stimulus, imageindices] = sortrows(perStimAtten');
imageroot = 'C:\Users\User\Desktop\Matlab\AnalysisScript\1';
images = cell(numel(imageindices), 1); %to store the images
for idx = 1:numel(imageindices)
imagename = sprintf('%d.tif', imageindices(idx));
images{idx} = imread(fullfile(imageroot, filename));
end
Do whatever you want with that cell array. Note that if all the images are the same size and with the same number of colour channels, then loading them into a 3D (greyscale images) or 4D matrix (RGB images) may be better.
0 commentaires
Voir également
Catégories
En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!