How do I use the cat function?

1 view (last 30 days)
Mackenzie Maher
Mackenzie Maher on 13 Dec 2021
Commented: Mackenzie Maher on 17 Dec 2021
HI everyone!
I created the following code to obtain certain data points (peaks). I'm trying to use the the cat function to get all of the peaks into one array (Allpeaks). However when i did this I got the erorr below:
fieldNames = fieldnames(MCR_full.MIB037.Reaches);
for k = 1 : 10
thisFieldName = fieldNames{k};
thisArray = MCR_full.MIB037.Reaches.(thisFieldName).kin;
x = thisArray(:, 1);
y = thisArray(:, 3);
Allpeaks=cat(peaks)
[peaks, locs]= findpeaks (y);
reachLimitArray= find (peaks >= 0.12);
if length(reachLimitArray )> 1
disp('There is at least two value above the limit.');
for i = 1 : length(reachLimitArray)
end
else
disp('All values are below the limit.');
end
end
Error using cat
Dimension argument must be a real, positive, integer scalar.
If anyone knows what this means and how to fix it your help would be greatly appreciated!
  2 Comments
Stephen23
Stephen23 on 13 Dec 2021
"Any ideas on how to do this?"
The standard approach is to use indexing into an array:

Sign in to comment.

Accepted Answer

Jan
Jan on 13 Dec 2021
Whenever you have an error for a specific command, read the help section at first:
help cat
% Or more exhaustive:
doc cat
You will see, that the first input must be the dimension, along which the list of folloing arrays is concatenated.
In your case cat(peaks) appears, before peaks is defined. This looks strange. I guess you want to replace:
Allpeaks=cat(peaks)
[peaks, locs]= findpeaks (y);
by
[peaks, locs]= findpeaks(y);
Allpeaks = cat(1, Allpeaks, peaks); % Or cat(2, ...) ?
  4 Comments
Mackenzie Maher
Mackenzie Maher on 17 Dec 2021
Thank you so much you are wonderful it worked!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!