Matlab Cell Arrays Help | Get Expert Assistance Now

In summary, the conversation discusses how to create a simple matrix in MATLAB with 6 columns to store onset times for different types of images. The suggested approach involves using a loop to extract the image name and onset time from a cell array and add them to the corresponding column in the matrix. The conversation also includes code snippets to demonstrate this approach.
  • #1
Krot_krot
1
0
Hi Matlab community and clever people
I desperately need help in matlab.
My data are stored as cell arrays (1x48 cells). Each cell contains 5 cells {1,1}, {1,2}...{1,5}.
Cells {1,1} contains image name and {1,3} contains onsets time.
I need to create a simple matrix in MATLAB with 6 columns (each column for each TYPE of image. Since there are 6 types of images: image1, image 2, image3..so there should be 6 columns) containing onsets for corresponding image.

to load this file in MATLAB I used two lines and formula:

clear all
uiopen('subjfmri1_1.res',1);
eventMatrix=loadlogfile('subjfmri1_1.res');

I would be very pleased for any help or suggestions
thank you in advance
 

Attachments

  • loadlogfile.m
    303 bytes · Views: 411
Physics news on Phys.org
  • #2
.You can use the following approach to create the matrix: % Create an empty matrix to store dataeventMatrix = [];% Loop over all cells in your data for i=1:length(data) % Get the image name from the cell array currentImageName = data{i}{1,1}; % Get the onset time from the cell array currentOnsetTime = data{i}{1,3}; % Check which type of image it is, and add the corresponding % onset time to the correct column in the eventMatrix if strcmp(currentImageName, 'image1') eventMatrix(end+1,1) = currentOnsetTime; elseif strcmp(currentImageName, 'image2') eventMatrix(end+1,2) = currentOnsetTime; elseif strcmp(currentImageName, 'image3') eventMatrix(end+1,3) = currentOnsetTime; elseif strcmp(currentImageName, 'image4') eventMatrix(end+1,4) = currentOnsetTime; elseif strcmp(currentImageName, 'image5') eventMatrix(end+1,5) = currentOnsetTime; elseif strcmp(currentImageName, 'image6') eventMatrix(end+1,6) = currentOnsetTime; end end % Finally, print out the eventMatrix disp(eventMatrix);
 

What is a cell array in Matlab?

A cell array in Matlab is a data structure that can hold different types of data, such as numbers, strings, or other arrays, in a single variable. It is similar to a regular array, but it can have varying sizes and types of data in each element.

How do I create a cell array in Matlab?

To create a cell array in Matlab, you can use the curly braces { } to enclose the data you want to store in the array. Each element should be separated by a comma. For example, to create a cell array with three elements, you would write: myCellArray = {'apple', 10, [1 2 3]};

What are the advantages of using cell arrays in Matlab?

Cell arrays in Matlab can be useful for storing and manipulating complex data, such as nested structures or multidimensional arrays. They also allow for more flexibility in data types and sizes compared to regular arrays.

How do I access elements in a cell array in Matlab?

To access elements in a cell array in Matlab, you can use the curly braces { } and specify the index of the element you want to retrieve. For example, to access the first element in a cell array, you would write: myCellArray{1};

Can I convert a cell array to a regular array in Matlab?

Yes, you can convert a cell array to a regular array in Matlab by using the cell2mat() function. This function will convert each element in the cell array to its corresponding data type and create a regular array with the same dimensions.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
18K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
8K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
Replies
4
Views
3K
  • Differential Equations
Replies
1
Views
7K
  • Programming and Computer Science
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Replies
109
Views
54K
  • Sticky
  • Feedback and Announcements
Replies
2
Views
495K
Back
Top