Error with splitting table into separate columns.
Show older comments
I am working with a 616x91 table that I am reorganising using:
x = table1(1:48:end,:);
y = x(:)
a = table1(2:48:end,:);
b = a(:)
and so on.... until
c = table1(48:48:end,:);
d = x(:)
Each data point is repeated (not an exact repition of data, just the data point) every 48 rows, hence the 48.
My issue is that each output variable (y,b,d etc.) variable should be a 1183x1 column however, the last 8 output variables output a 1092x1 column. I.e. the last 8 variables are:
m = table1(41:48:end,:); q = table1(48:48:end,:);
n = m(:) ......to..... p = q(:)
Can anyone explain why this is happening?
12 Comments
You don't have enough columns -- 2*48 = 96 and you have only 91...so your second selection is 5 columns fewer than the first.
I'd suggest it's not likely you need to actually create the new variables and certainly not as named-sequentially separate variables...use dynamic addressing to select the columns needed for working at a time or, at worst, use an array or cell array.
ANDREW Feenan
on 28 Jul 2021
"Would you be able to explain further?"
In general, splitting data up makes it harder to process. It is usually easier to loop over one set of data and use indexing to select the required data for processing, or by using tools specifically designed for operating on groups within data sets:
Creating lots of separate variables is very unlikely to be a good approach.
ANDREW Feenan
on 28 Jul 2021
ANDREW Feenan
on 28 Jul 2021
dpb
on 28 Jul 2021
Data generally helps for reading files, etc., but if it's just an array the data itself isn't of much import -- "parts are parts!".
What we really need to know is what your end purpose is in accessing the data in this fashion and what you would be doing with it if you could do what you envision.
The point there is, we can probably (almost certainly?) point you in a way to accomplish the end; there may not be any better way to do what you describe, but that is, as Stephen points out, almost certainly not "the MATLAB way" to implement whatever it is that you're try to code efficiently.
So, data may be of some help in that it would illustrate a particular case, but what we really need is a description of what the end result needs to be, not how to get there.
ANDREW Feenan
on 29 Jul 2021
dpb
on 29 Jul 2021
I didn't say to not append a file... :)
What are you going to do in Excel that couldn't be done more simply in MATLAB?
ANDREW Feenan
on 29 Jul 2021
dpb
on 29 Jul 2021
Just a small(ish) template that outlines the shape/content with randomized/obfuscated names, etc., is enough. It doesn't even have to be all 96 or 48 or whatever, just enough that somebody can load a file of the desired general structure without having to try to make it up for themselves.
We can try from the description alone, but having something that actually is in the actual format is much simpler than trying to figure it out...remember we don't have all the inate knowledge of the problem you have; it's harder to visualize from just the words although I'm sure it could be done; I'm personally not inclined to go try to build a sample spreadsheet from the description, sorry... :)
ANDREW Feenan
on 29 Jul 2021
ANDREW Feenan
on 29 Jul 2021
Accepted Answer
More Answers (0)
Categories
Find more on Spreadsheets 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!

