MATLAB: Writing data into a .csv file from App Designer

app designercsvsave data

Good day!
My code reads in data from a .csv file as a startup function and displays it in a table, which works fine. Although, there are a bunch of edit fields that the user fills in, and then clicks on a "Save Data" button that shows the new data on the table, but should also save it to the csv file. When I run the code and try it out, an error message pops up in the matlab command window saying that permission is denied for the csv file, or that it can simply not find it (but it is saved in my matlab folder on my computer). ANY help on this would be much appreciated!! Thank you!
Below is the code I have for it so far:
function SaveDataButtonPushed(app, event)
name = app.MatName.Value;
e1 = app.LongElasMod.Value;
e2 = app.TransElasMod.Value;
g12 = app.ShearMod.Value;
V12 = app.PoissonRatio.Value;
xp = app.LongComp.Value;
x = app.LongTens.Value;
yp = app.TransComp.Value;
y = app.TransTens.Value;
s = app.UltShear.Value;
nr = {name e1 e2 g12 V12 xp x yp y s};
app.UITable.Data = [app.t;nr];
app.t = app.UITable.Data;
Tnew = [app.t;nr];
size(Tnew);
csvwrite('StrengthsMaterialsList.csv', Tnew);
end

Best Answer

Hi,
It is recommended to use writematrix instead of csvwrite, to write any matrix to a file. Can you try using the forementioned method in your case.
Also, I am not able to make sense of the following statements in your code. I feel the following statements are redundant. If the issue is not solved using writematrix, It would help if you can explain what exactly do you intend to do with the following code.
%First question what do app.t has? I assume it has UITable's data
nr = {name e1 e2 g12 V12 xp x yp y s};
app.UITable.Data = [app.t;nr]; %this looks as if you are updating UITable.
app.t = app.UITable.Data;
Tnew = [app.t;nr]; %Isn't this redundant, as app.t already UITable data which is appended with 'nr'
size(Tnew);