matlab运行很多columns,将excel文件中的2列循环到matlab中(Looping 2 columns from an excel file into matlab)...

将excel文件中的2列循环到matlab中(Looping 2 columns from an excel file into matlab)

我是MATLAB的新手,并且一直在使用Stack Overflow和其他手册作为资源来学习,但是我已经被困在以下很长一段时间了!

对于我的实验,我以加扰的顺序向参与者呈现不同的图像(编号从1到324)。 我的目标是用显着性图覆盖他们的凝视模式。

所以我在MATLAB中有两个我想要FOR循环的变量:“z”是乱码表示顺序,例如:[95,147,1 ...](总共324个数字)“i”是记录的凝视模式的顺序(按顺序从1到324)

我试过使用2 for循环,Ex。 对于z = [95,147,1 ....],对于i = 1:324%打开并创建“z”%开放凝视路径的显着性映射为“i”%结合两个%保存

我所希望的是z = 95将与i = 1配对,z = 147将与i = 2配对,依此类推,但是对于所有z =,for循环经历i = 1:324 95然后继续z = 147并再次通过i = 1:324 ...

我曾想过将z和i值放入表中,以便ImageOrder ScatterOrder 95 1 147 2 1 3

但是,我一直遇到特定步骤的困难。 我想知道是否有人有任何建议。 对不起,如果解释一直混乱! 如果有任何疑惑请评论! 非常需要你的帮助。

I am very new to MATLAB and have been using Stack Overflow and other manuals as resources to learn, however I have been stuck on the following for a very long time!

For my experiment, I am presenting participants with different images (which are numbered from 1 to 324) in a scrambled order. My goal is to overlay their gaze pattern with a saliency map.

So I have two variables in MATLAB that I want to FOR loop: "z" is the scrambled presentation order, ex: [95,147,1...] (324 numbers in total) "i" is the order of gaze patterns recorded (it goes in order from 1 to 324)

I have tried use 2 for loops, Ex. for z=[95,147,1....] for i=1:324 %open and create saliency maps for "z" %open gaze pathways for "i" %combine both %save

What I was hoping was that z=95 would be paired with i=1, z=147 would be paired with i=2 and so on, however what happens is the for loop goes through i=1:324 for all of z=95 and then continues to z=147 and goes through i=1:324 again...

I have thought of putting z and i values into a table such that ImageOrder ScatterOrder 95 1 147 2 1 3

However, I have been having difficulty for the specific steps. I was wondering if anyone had any suggestions. Sorry if the explanation has been confusing! If there are any confusions please comment! Your help is much needed.

原文:https://stackoverflow.com/questions/30446126

更新时间:2020-01-05 00:33

最满意答案

我实际上想出了一个方法,

我设置

s1='A2' %first cell of the image order column

s2='B2' %first cell of the scatter order column

然后我为i = 2创建一个for循环:___(我希望结束的行号)

s1=['A', num2str(i)]; %Loops through rows of A

s2=['B', num2stri(i)]; %Loops through rows of B

x1=xlsread('filename.xls',[s1,':',s2]);

a=x1(:,1) %Taking image order of every row

b=x1(:,2); %Taking scatter order of every row

使用'a'和'b',我可以在循环时访问相同行中的两个不同变量。

I actually figured out a method,

I set

s1='A2' %first cell of the image order column

s2='B2' %first cell of the scatter order column

Then I create one for loop for i=2:___(The row number I want to end on)

s1=['A', num2str(i)]; %Loops through rows of A

s2=['B', num2stri(i)]; %Loops through rows of B

x1=xlsread('filename.xls',[s1,':',s2]);

a=x1(:,1) %Taking image order of every row

b=x1(:,2); %Taking scatter order of every row

With the 'a' and 'b' then I can access two different variables in the same rows while it loops.

2015-05-29

相关问答

为每个文件添加一个Excel源代码以加入它们的“联合所有”任务,因此如果您的第一个Excel上有20行而第二个上有30行,那么最终会有50行: 要设置源路径和目标路径,只需双击每个任务并设置连接管理器 编辑: 如何在此处读取excel文件的示例 add an Excel source for each of your files an a "union all" task to join them, so if you have 20 rows on your first excel and 30

...

我将演示如何以矢量化的方式从数据中提取相关的行。 我将离开阅读/写入excel文件的部分给你(它应该是直截了当的): %# sample data

data = rand(3*10,6);

%# for each three rows, find the min of second column, and get the row index

[r c] = size(data);

d = permute(reshape(data',[c 3 r/3]),[2 1 3]); %'# split

...

您正在添加不同大小的矢量。 当你将t添加到m个向量中的一个时,m个向量与t的大小相同吗? 您可以输出参与add操作的所有变量的长度以进行调试。 如果不这样做,请使用size函数。 1xm和mx1矩阵也不会添加。 You're adding vectors that are different sizes. When you add t to one of your m vectors, are the m vectors the same size as t? You can output the

...

尝试删除工作表中的所有空列/行,并在数据后显式删除多个列/行。 Matlab似乎有“空”列/行的问题。 Try removing any empty columns / rows you have in your sheet, as well as explicitly delete several columns / rows after your data. Matlab seems to have a problem with "empty" columns / rows.

我实际上想出了一个方法, 我设置 s1='A2' %first cell of the image order column

s2='B2' %first cell of the scatter order column

然后我为i = 2创建一个for循环:___(我希望结束的行号) s1=['A', num2str(i)]; %Loops through rows of A

s2=['B', num2stri(i)]; %Loops through rows of B

x1=xlsrea

...

对于这种东西,您可以直接转到Microsoft文档。 这些应该可以帮到你: http://msdn.microsoft.com/en-us/library/office/ff841185.aspx http://msdn.microsoft.com/en-us/library/office/ff198017.aspx 基本上,您可以在此处发出命令,就像在Excel GUI中的SaveAs对话框中一样。 For this kind of stuff, you can directly go to t

...

基本上你需要读取整个数据,最好是原始(单元格)格式,添加缺失的行(相对于索引)并回写。 根据您的问题,此代码可能有效 - % NOTE: We are assuming that the indexing starts with 1

% Read data from input excel file with missing indices

[num,txt,raw] = xlsread('input.xls');

% Error-checking

if (size(num,1)-num(en

...

您将需要使用xlsread来获取数据,然后您可以在MATLAB中执行所有分析。 % Each column is the same as your excel columns.

data = xlsread(filename);

这将返回一个M x 3矩阵,其中列是您的纬度,经度和phi,行是您的Excel工作表中的行。 然后,您可以使用逻辑索引来获取感兴趣的值。 所以对于你的问题中的例子,你会有类似的东西。 touse = data(:,1) >= 10 & data(:,1) < 20 &

...

下面是你可能想要用xlswrite [1]做的一个工作示例: filename = 'testdata.xlsx'; % Filename to save average values in

for k = 1:10 % Looping for 10 iterations

sheet = 2; % Selecting sheet2

Avg = randi([1 10],1,1); % Generating a rando

...

xlswrite的用法如下: xlswrite(filename,A,sheet,xlRange)

其中filename是文件名的字符串,A是数据,sheet是工作表编号的整数,范围是范围的字符串,例如'C1:C2',其中C1和C2是定义区域的两个相对的角写。 例如,'D2:H4'表示两个角D2和H4之间的3乘5的矩形区域。 因此,对于同一张纸的2列中您想要的2个向量: filename = 'pathtofile.xls';

A = vector1;

sheet=1;

xlRange = 'A

...

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值