Create a new table by transforming data in existing table with few lines (maybe just one)
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a table (not matrix) that has data read in from Excel. I want to change some of that data by multiplying by certain values. So for the first row in the table:
TransFluorData(1,3:8) = FluorData(1,3:8) * dx/FluorData(1,2)
I'd like to be able to do this for all rows in the table FluorData. Note, that data in columns 1 and 2 are not to be changed, just from columns 3 to the end of the number of columns (8 in the example code). So I want the existing value in each cell of FluorData within the bounds of all rows but only columns 3 through 8 to be multiplied by dx/FluorData(i,2) where i is the row number (the above code only looks at row 1).
As I understand it, Matlab should allow me to do this in one or two statements that don't require a do loop or for/next loop as would be required in Visual Basic, for example. Also, I suspect that I need to use braces but I'm not sure for which terms.
0 comentarios
Respuestas (1)
dpb
el 2 de Dic. de 2021
Editada: dpb
el 2 de Dic. de 2021
The above syntax is for a variable/matrix/array, NOT for a table if a MATLAB table object is, indeed, what you have. We can't tell; you didn't show us how you read the data from the Excel file. If you used readtable, then unless you've done something afterwards, it is, indeed, a table.
I'll presume is so, but will have to make up a variable name since you didn't provide that, either--I'll presume the names above are names of variables inside the table.
tYourtable.TransFluorData(:,3:8)=tYourtable.FluorData(:,3:8).*dx./tYourtable.FluorData(:,2);
The above also assumes there is an existing variable TransFluorData in the table and also that these variables are arrays inside the table and there are not six separate variables.
Also NB the "dot" operators on the math operations to work on an element-by-element basis instead of as matrix math operations.
The odds of the above working "out of the box" given the assumptions having to make are, I'd guess, fairly low. As per usual, having actual information on the data structure would make the odds of success much higher.
Executing
tTmp=head(tYourTable);
save Sample tTmp
then attaching the resultant "Sample.mat" file would make it possible for somebody to actually do something with the real table structure as it exists.
ADDENDUM: There's a long section in the documentation for the table object that goes into all the possible addressing modes of the table -- it's invaluable.
0 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!