How to load a folder according to a vector into matlab?

4 次查看(过去 30 天)
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 个评论
Sigal Cohen
Sigal Cohen 2017-8-27
Let's try this way:
This is what I have so far:
load('C:\Users\User\Desktop\sif files\Trial3\datafile6.mat');
[yy ii]=sortrows(perStimAtten');
for n=1:length(ii)
filename = sprintf('%d.tif', ii(n));
load(fullfile('C:\Users\User\Desktop\Matlab\AnalysisScript\1', filename));
end
But I get an error:
Error using load Unknown text on line number 1 of ASCII file C:\Users\User\Desktop\Matlab\AnalysisScript\1\6.tif "I*".
Error in AnalysisScript (line 14) load(fullfile('C:\Users\User\Desktop\Matlab\AnalysisScript\1', filename));
Which is odd because the file does exist on the path.
Maybe if I'll figure out what this error is I'll be able to proceed.
Thank you,
Sigal.
Jan
Jan 2017-8-27
@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.

请先登录,再进行评论。

回答(1 个)

Guillaume
Guillaume 2017-8-27
编辑:Guillaume 2017-8-27
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.

类别

Help CenterFile Exchange 中查找有关 Scripts 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by