You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to split data of a .mat file into trainH trainY testH testY as shown in picture
8 views (last 30 days)
Show older comments

8 Comments
Arif Hoq
on 9 Mar 2022
even we can't see the dimension.
trainH=1000 X 9
trainY= 1000 X ?? what ?
testH=473 X 9
testY=473 X 1
Arif Hoq
on 9 Mar 2022
it looks cmc.mat is a mat file with 4 variables(trainH,trainY,testH,testY)
if you open cmc.mat file you can get these 4 variables. why do you want to split these variables again from cmc.mat?
load('cmc.mat')
uma
on 9 Mar 2022
I don't need to split it i just show how i want my dataset. i'm having another another dataset where i need to split.
Benjamin Thompson
on 9 Mar 2022
You will need to post your dataset and more comments about what you want to do in order for the Community to offer a helpful answer.
uma
on 9 Mar 2022
Edited: Stephen23
on 10 Mar 2022
I have a .mat file dataset containg four variables trainH trainY...as you can see in the above picture. Now want these fours variables in another dataset in the same way...may be this is done in the CSV file.
I have attached both my .csv and .mat dataset I just want something like this
struct with fields:
trainH: [1000×9 double]
trainY: [1000×1 double]
testH: [473×9 double]
testY: [473×1 double]
Accepted Answer
Arif Hoq
on 9 Mar 2022
My guess:
1st step: load your cmc.mat file in Variable A as a struct.
2nd step: extract your 4 variables from struct A.
A=load('cmc.mat');
trainH=A.trainH ;
trainY=A.trainY;
testH=A.testH;
testY=A.testY;
9 Comments
uma
on 10 Mar 2022
what would be in the field trainH tainY(A.trainY).... that is non existant field.
uma
on 13 Mar 2022
I have attached both my .csv and .mat dataset I just want something like this
struct with fields:
trainH: [1000×9 double]
trainY: [1000×1 double]
testH: [473×9 double]
testY: [473×1 double]
Arif Hoq
on 13 Mar 2022
It does not make any sense. segment.mat file has 2310 rows and 25 columns. you can get your 4 variables (trainH,trainY,testH,testY) randomly. but you should make us clear which row and column want to extract from segment.mat .
uma
on 13 Mar 2022
First I want to extract all rows and colunms from the segment.mat and want to store in TrainH
uma
on 14 Mar 2022
In workspace we will get a variable trainH but now I want this variable inside in the mat file just like above cms mat file contains.
Arif Hoq
on 14 Mar 2022
move your mouse cursor to the variable trainH.
Right Click > save as> write your fileName (cmc)>save
More Answers (0)
See Also
Categories
Find more on Workspace Variables and MAT-Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)