iWork Numbers 09 increment a cell value - iwork

I am working with Numbers 09 and Applescript.
I want to add a value in one cell to an existing value in another cell, replacing the existing value with the sum as a value. This would be similar to the copy/paste-add command in Excel. Thanks for your help.
-Rob

Got it...
I was trying to make it too difficult. Calling back to my ancient training in FORTRAN and Pascal.
copy 0.1 to xno
tell application "Numbers"
activate
tell document 1
tell sheet 1
tell table 1
copy the value of cell "B2" to xno
xno - 200
copy xno to the value of cell "C2"
end tell
end tell
end tell
end tell

Related

Xlsread sheet in for loop

I have a number of excel sheets I would like to cycle through enclosed in a for loop, with sheet name a through A to X. Is this possible?
I tried this:
for letter='A':'X'
[num,txt,raw] = xlsread('Grouting_sum_final.xlsx','%s',letter);
% Lots of code below here (not relevant for the problem)
end
Yes, it is, but you do not need the '%s' part of your line.
If you go to the documentation website, you will find that you have to pass as first argument the excel file name and as second the sheet name.
So your code should read something like:
for letter='A':'X'
[num,txt,raw] = xlsread('Grouting_sum_final.xlsx',letter);
% Lots of code below here (not relevant for the problem)
end
Also, I am assuming you are aware that you keep on overwriting your data retrieved from the Excel sheet.

Loading a cell in Matlab

I have saved a Matlab file in the computer memory called data.mat. The file is structured as a cell with dimension 13x1. To save the file, I have used the command save('data.mat', 'data').
Now, I want to load the file and transform it.
This is what I am doing at the moment
%Load data
load data
%Transform data
for n=1:13
data{n}(:,1)=rand(10,1); %replace first column
end
However, I get as a warning message on the Matlab script:
"The variable data appears to change size at every loop iteration. Consider preallocating for speed".
In short, the script does not recognise that I have loaded a cell.
How can I fix this? It is not an error message and Matlab does OK when running the code. I just want to remove the warning thing.
You're getting this warning because the Editor has no way of knowing what format your variable data will have until it is loaded from the MAT file. Since data isn't defined, it likely assumes you are making it from scratch and issues the warning. If you're certain you aren't going to be growing your cell array (i.e. you will only ever modify existing cells), you can just suppress the warning by adding this as the first comment on that line:
%#ok<SAGROW>
Or by right clicking on the highlighted word data and selecting the options "Suppress.. On This Line", which will add the comment for you.
More information on this can be found in the documentation.

Reading the sheet name of a .xls file with Matlab

I have got 30 files named Data1.xls to Data30.xls. In each file, there are two sheets I'm interested in. The first is called 'Ergebnisse' where I get the name of the second sheet, which is important to me. This sheet changes its name. My problem here is that I don't know how to tell Matlab to use the changing sheet name.
What i got so far:
liste = dir('*.xls'); % how many files in the folder
liste=struct2cell(liste);
liste=liste(1,:)';
for i=1:length(liste) % i=number of files
filename=['Data' num2str(i) '.xls'];
[num,txt,raw]=xlsread(filename,'Ergebnisse');
sheet=txt(3,1);
[num,txt,raw]=xlsread(filename,sheet);
end
The answer for sheet is 'T4_quer_3' which I would normally write into the next xlsread but it doesn't work.
Thanks for your help
you dont need the cell txt(3,1), but its content. so either go for
sheet=txt{3,1};%notice the other brackets
or you go for
[num,txt,raw]=xlsread(filename,sheet{:}); %{:}content of a cell

How to read this line in MATLAB?

I came across the following lines in MATLAB:
m = dir(fullfile(dataset,'*.png'));
m = {m(~[m.isdir]).name};
I understand that the first line is trying to obtain the .png files from a directory. But, what is the second line trying to perform? isdir seems to determine that an input is a directory. That's what I new for that part. But, what is the line trying to perform?
Thanks.
The second line is getting all files that are not a directory and then getting the respective names and storing them into a cell array
m.isdir indicates if it is a folder or not
returns 1 if it is, 0 if not.
~[m.isdir] will indicate which of the values returned from isdir was a 0.
m(~[m.isdir]) grabs all objects in m determined by the logical indexing done above
m(~[m.isdir]).name gets the names of all of them
{m(~[m.isdir]).name} stores them all in cell array
Hopefully this step by step walkthrough helps.
While I am not sure why the second line is necessary because the fullfile(dataset,'*.png') should only return paths that end in .png, which will not be a folder, I guess it is good to check.

Unable to write to an .xls file (MatLab)

I wanted to edit a certain .xls spreadsheet in MatLab by, say, inserting number 3 into cell H4. I typed out following code:
xlswrite('list.xls', 3, 1, 'H4')
but it doesn't change anything. The spreadsheet is left seemingly untouched but xlswrite returns 1 as the write succeeded output...
Any ideas on what might be going on?
Cheers.
Try with this:
xlswrite('test',3,'H4:H4')