필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
Sigal Cohen
Sigal Cohen 2017년 8월 23일
편집: Guillaume 2017년 8월 27일
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